I would like to pass parameter from view to controller in cshtml page.
This is the code I have:
<script type="text/javascript">
function Test() {
$.get(
"@Url.Action("UpdateReport/", "Report")"
);
}
</script>
<h2>Reports</h2>
@foreach (var item in Model)
{
<div>@Html.ActionLink(@item.Name, "ActionCall", "Report", new { Id = @item.Id }, null )</div><br /><br />
<input type="button" class="button1" value="Insert" />
<input type="button" class="button1" value="Delete" />
<input type="button" onclick="Test()" class="button1" value="Update" />
}
When I click the update button I would like to pass the @item.Id to the controller action via the JS code I have. The code is stepping in to the controller action now, but without parameters. I want to pass a parameter as well.
Thanks in advance for every advice, Laziale
public ActionResult UpdateReport(string name)
{
return View("Index");
}
you can use $.post
and bind the item id to your input