How to Pass parameters to Html.ActionLink
I have two input control and and one Html.ActionLink control on my page. How do i pass the value of these input control as parameter to Controller Action.
<in开发者_JAVA百科put id="txtName" value="MyName" type="Text"/>
<input id="txtAge" value="20" type="Text"/>
<%: Html.ActionLink("Add", "AddName", "EditProfile", new{ --- What to Pass--}, new { @Class = "openDialog", data_dialog_id = "AddCarrierDialog", data_dialog_title = "Add Carrier" })%>
My Controller take two parameter to show detail
[HttpPost]
public ActionResult AddName(string Name, int Age)
{
return PartialView("ShowData");
}
I am not able to pass txtName and TxtAge values to controller Action. Can Anyone help me out. Thanks in Advance!!!
You will need javascript in order to achieve that. A better approach would be to use an html <form>
instead of an action link as it will automatically send the values that the user entered in the input fields to the server:
<% using (Html.BeginForm("AddName", "EditProfile", FormMethod.Post, new { @class = "openDialog", data_dialog_id = "AddCarrierDialog", data_dialog_title = "Add Carrier" })) { %>
<input id="txtName" value="MyName" type="text" />
<input id="txtAge" value="20" type="text" />
<input type="submit" value="Add" />
<% } %>
精彩评论