Question

The route for my view is like this:

http://localhost/project1/join/register/ABCDEFGH/12345678

The last two parts are the parameters which I accept as part of my route. What I want to do now is to render a form onto the view which has a post method which retains that url.

I am using the BeginForm HTML helper as follows:

using (Html.BeginForm(
    "Register", 
    "Join", 
    new { ApplicationKey = Model.ApplicationKey, UserId= Model.UserId}, 
    FormMethod.Post, 
    new { @class = "form-horizontal", @role = "form" }))

This renders the forms action tag with a URL as follows...

http://localhost/project1/join/register?ApplicationKey=ABCDEFGH&UserId=12345678

Is there any way to use the form helper and to retain the format of my route? I can make this work with query string parameters but there are other considerations which mean it would be better if I could get the helper to format the route as it was originally used to access the page.

Thanks.

Was it helpful?

Solution

The reason it isn't formatted nicely is because it hasn't found a matching route that fits all the parameters being passed.

You could try Html.BeginRouteForm and use a named route to do it.

http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginrouteform(v=vs.118).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top