When you press submit button then only HTML inputs are passed to server (typically as POST data). So if you want to send to action method some ID that user shouldn't see then you can use hidden input:
<%= Html.Hidden("id", obj.ProductID) %>
Or you can specify ID directly in action atributte of form element:
<% using(Html.BeginForm<ProductController>(c => c.UpdateProduct(obj.ProductID)) { %>
<%-- your form here --%>
<% } %>
This last example uses
ASP.NET MVC Futures assembly. If you want to use it then you have to reference it and add
Microsoft.Web.Mvc into namespaces in your web.config file.
Don't forget to click "Mark as Answer" on the post that helped you.
abhi.singh19...
Member
8 Points
57 Posts
how to pass a value to action
Nov 28, 2008 04:42 AM|LINK
hi
this is the top part of my code
<
form method ="post" action ="/Products/Update"> <table > <tr> <td>Product Id:
</td><td><%= obj.ProductID%></td> </tr> <tr>now i want that when i press the submit button the product id should go to the update action .how can i achive this???
bhadelia.imr...
Contributor
3191 Points
533 Posts
Re: how to pass a value to action
Nov 28, 2008 07:03 AM|LINK
You can change the action by setting the property of forms, as bellow
document.forms[0].action
[MCTS]
Born to fly High
http://knowledgebaseworld.blogspot.com/
Augi
Contributor
6730 Points
1142 Posts
Re: how to pass a value to action
Nov 28, 2008 08:17 AM|LINK
When you press submit button then only HTML inputs are passed to server (typically as POST data). So if you want to send to action method some ID that user shouldn't see then you can use hidden input:
<%= Html.Hidden("id", obj.ProductID) %>Or you can specify ID directly in action atributte of form element:
IMHO best way how to do it is this:
This last example uses ASP.NET MVC Futures assembly. If you want to use it then you have to reference it and add Microsoft.Web.Mvc into namespaces in your web.config file.
nbkhubani
Member
110 Points
45 Posts
Re: how to pass a value to action
Nov 28, 2008 08:50 AM|LINK
Use following code at your aspx page
<form method="post" action="/Products/Update/<%=obj.ProductIDId %>""> <table ><
tr><
td> Product Id: </td><td><%= obj.ProductID%></td></
tr> <tr><
td> <input type="submit" value="Submit" /></td></
tr></
table> </form>and following at your Controllers
public ActionResult Update(int productID)(n)Code Solutions, Licence Certifying Authority