In my .cshtml, I’m painting some data. Then I have a repy textbox and a button for people to reply to a customer service thread.
@using (Html.BeginForm("Update", "CustomerServiceMessage", FormMethod.Post, new { id = 0 }))
...
}
When I submit, I don’t get 0 when it hits my Update actionmethod, I get the id of the parent Service message I painted above the reply box. So it’s like an email/forum thread but even though I hard code the = 0 the Update method is getting an Id of the parent message that I painted on the screen (rendered).
Can’t figure out why.
That’s normal, you never send this id to your server. You just used the wrong overload of the
Html.BeginFormhelper:and you ended up with the following markup (assuming default routes):
See the problem?
And here’s the correct overload:
which generates (assuming default routes):
Now, you will get your
id=0inside the corresponding controller action.By the way you could make your code more readable and avoid this kind of mistakes by using C# 4.0 named parameters: