I have an action in my controller:
public PartialViewResult MyAction(int? myId, int? myId2)
{
MyModel model = new MyModel() { MyId = 10, MyId2 = 20 }
return PartialView(model);
}
Here is my view:
@model StartSite.Models.Shared.MyModel
@using (Html.BeginForm())
{
@Html.HiddenFor(m => m.MyId)
@Html.HiddenFor(m => m.MyId2)
<p>
<input type="submit" value="Submin" />
</p>
}
Lets call MyAction with params myId=1&myId2=2. But the model is created with different values new MyModel() { MyId = 10, MyId2 = 20 }. And what should be rendered in view? As I expect it should be:
<input id="MyId" name="MyId" type="hidden" value="10">
<input id="MyId2" name="MyId2" type="hidden" value="20">
But in fact the result is:
<input id="MyId" name="MyId" type="hidden" value="1">
<input id="MyId2" name="MyId2" type="hidden" value="2">
As I guess the Html.HiddenFor takes values not from my model but from Reauest.QueryString which is myId=1&myId2=2 at the moment the view is rendered.
Why it happens? Is it expected behaviour?
UPDATE 1: I've edited my question to be more clear.