简体   繁体   中英

get value from a hidden field in mvc view, value already set

@Html.Hidden("cinDays") 

From inspect element:

<input id="cinDays" name="cinDays" type="hidden" value="127">

The value from #cinDays I want to be a parameter for a.cs C# method. This method is called inside an @if statement in my view

In the JavaScript function you can access the value like below:

function yourfunc() {
    let param = $("#cinDays").val();   
    // Now using the `param` value 
    ... 
}

As I understand cinDays is a part of view model so you can access to this property like this

...

<div>
      @if(someFunc(Model.cinDays)) {
       //some code
      }
</div>

...

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