I am really really confused rigthht now, because I thought that @Html.HiddenFor(x => x.Id) and
is the same thing, except for some benefits of the first variant. But If I use the first variant and look into generated html value of input is always = 1, and if I use the second variant - everything is OK.
So here is my view model:
public class CheckListViewModel
{
public int Id { get; set; }
public DateTime CheckTime { get; set; }
public List Questions { get; set; }
}
My view code:
@using System.Diagnostics
@using WebCheckList.Models
@model CheckListViewModel
@using (Html.BeginForm("Submit", "CheckList", new {ReturnUrl = ViewBag.ReturnUrl}, FormMethod.Post, new {@class = "form-horizontal", role = "form"}))
{
//this one does not work. It generates the same html code as
// a line below it, only difference is that its value is always = 1
@Html.HiddenFor(x => x.Id);
//When I change it to this - everything works.
...
MVC version is 5.2.0.0
Please, tell me, what have I done wrong, and why the @Html helper does not work properly?
UPDATE:
Contoller looks like this:
public ActionResult Questions(int id)
{
return Create(new CheckList(), id);
}
public ActionResult Create(CheckList checkList, int checkListsTypeID = 2)
{
_db.CheckLists.Add(checkList);
_db.SaveChanges();
var checkListViewModel = new CheckListViewModel {Questions = questions, Id = checkList.ID, CheckTime = checkList.CheckTime};
return View("Details", checkListViewModel);
}
Is my problem happening because I return one method result from another?