@html.hiddenfor id name,c# - @Html.HiddenFor(x => x.Id) Does not work, but <input type="hidden" valu...

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?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值