KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
With ASP.net MVC is it possible to POST a form to a controller action which includes parameters not in the form, but from the URL? For example The Action method in GroupController: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(int idOne, int idTwo, Model model) { ... } The route: "{controller}/{action}/{idOne}/{idTwo}" Posted URL: /Employee/Show/1/42 In this example, the form is being posted to a different controller, the model has the correct value, however the other parameters have default values 0. The behavior I was expecting is that the ModelBinder would see that I have two parameters that match the given route, and assign the current values of 1 and 42 to the parameters in the same same way a GET operation works. Is this behavior not supported, or am I missing something? EDIT : To be clear, the form on the Show view for the controller Employee contains a form which is posting to a different controller. We can call it Group . The form action URL looks like this /Groups/Create/0/0 The form is declared as follows Html.BeginForm("Create", "Groups") After trying many different overloads for Html.BeginForm I have found that the parameters are only mapped when the form action URL matches the current URL in the browser address bar. So if i navigate to the URL /Groups/Create/1/42 I will have a new form. If I then submit the form, the URL route values are passed to the POST action.
Tags (comma-separated)
Save Edits
Cancel