Good day. How to make it so that when you click on the stock in the table (anywhere in the line), it goes down and details appear under it (or just the edit page opens)?
There is such an ASP page, with a table generated in a foreach loop:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <%@ Import Namespace="Tracker.Models" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> <%=ViewData["Title"]%> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script> <script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script> <script src="/Scripts/jquery-1.5.1.js" type="text/javascript"></script> <script src="/Scripts/listing.js" type="text/javascript"></script> <h2><%=ViewData["Title"]%></h2> <%=Html.ActionLink("Add New", "Add")%> <table> <tr> <td>Title</td> <td>Created Date</td> <td>Desciption</td> <td>ID</td> </tr> <% foreach (Task t in (IEnumerable<Task>) ViewData["Tasks"]) {%> <tr> <input type="hidden" class="rowID" value="<%=t.TaskId%>"/> <td><%=t.Title%></td> <td><%=t.CreatedOn.ToShortDateString()%></td> <td><%=t.Text%></td> <td><%=t.TaskId%></td> </tr> <% }%> </table> </asp:Content> And such a JS:
<script> $(document).ready(function() { $('table.values tr').click(function() { $.post("/Task/Edit/", { taskID: $(this).find('input.rowID').val() }); }); </script> In line:
<input type="hidden" class="rowID" value="<%=t.TaskId%>"/> the ASP file must pass the t.TaskId parameter to the script. The script, in turn, must take a value, and open the edit page by passing the Id of the selected line to it. But this code does not work. Help me figure out what exactly is not written correctly? When you start the application, there is no reaction to the .click event along the lines of the table.
To catch onClick you need javascript, I understand correctly? Otherwise, how to catch a click on the desired row of a dynamically created table?
How on event onClick to send ajax get request to the created action in the controller?