简体   繁体   中英

ASP.NET MVC 4: Changing the Value of a Hidden field in Javascript

I have a hidden boolean field :

@Html.HiddenFor(x => x.IsTurkey)

In jQuery script I try to change it:

$("@Html.IdFor(x => x.IsTurkey)").val("False");

But on the post back IsTurkey is not changed:

    HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Search(TurkeyModel model)
    { ...}

Using jQuery as above, how do I change the value of a hidden boolean field in MVC 4 ?

确保在Jquery选择器中包含前导#,因为MVC HtmlHelper不会输出它。

我不确定您IdFor的确切代码,但是您可以执行以下操作:

$("#IsTurkey").val(false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM