Reputation: 13655
I am using MVC3 Jquery and AJAX to produce something like List/Details view.
Now I have some code like this:
$(document).ready(function () {
$('#example tbody tr').click(function () {
alert('row was clicked');
$('#Container').load('../task/create/').fadeIn("slow");
});
});
My HTML is as following
<table id="example" border = "2">
<thead>
<tr style="border-style:solid" class="simplehighlight">
<th>
Name
</th>
<th>
Description
</th>
<th>
tblStatu
</th>
<th>
DueDate
</th>
<th>
AssignedTo
</th>
<th>
CreatedOn
</th>
<th>
CreatedBy
</th>
<th>
ModifiedOn
</th>
<th>
ModifiedBy
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr style="border-style:solid">
<td style="border-style:solid">
@item.Name
@*@Html.DisplayFor(modelItem => item.Name)*@
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.tblStatu.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.DueDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.AssignedTo)
</td>
<td>
@Html.DisplayFor(modelItem => item.CreatedOn)
</td>
<td>
@Html.DisplayFor(modelItem => item.CreatedBy)
</td>
<td>
@Html.DisplayFor(modelItem => item.ModifiedOn)
</td>
<td>
@Html.DisplayFor(modelItem => item.ModifiedBy)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.TaskId }) |
@Html.ActionLink("Details", "Details", new { id = item.TaskId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.TaskId })
</td>
</tr>
}
</tbody>
Now, How can I add parameter in my URL task/..... according to the selection if the row of the table?
Upvotes: 0
Views: 663
Reputation: 24236
Something like (not tested) -
$(document).ready(function () {
$('#example tbody tr').click(function () {
alert('row was clicked');
var rowid = $(this).attr("id");
$('#Container').load('../task/create/',{rowid: rowid}).fadeIn("slow");
});
});
That should use the [data] parameter of the load function to pass some data back to the url you are calling - the data will be POSTed back.
EDIT
Here's the final working code -
$(document).ready(function () {
$('#example tbody tr').click(function () {
var rowid = $(this).find('td#Name').html();
//alert(rowid); // rowid = 1;
$('#Container').load('../task/edit/' + $.trim(rowid)).fadeIn("slow");
});
});
Upvotes: 1