无法获取mvc中的隐藏字段值

Unable to Get the hidden field value in mvc

本文关键字:隐藏 字段 获取 mvc      更新时间:2023-09-26

当我在asp.net web表单上执行下面提到的代码时,我正在获取隐藏字段customerDeviceIdReferenceCode的值。

<form id="form1" runat="server">
    <div>
      <input type="hidden" id="customerDeviceIdReferenceCode" name="customerDeviceIdReferenceCode" value=""/>
    </div>
    </form>
    <script type="text/javascript">
        //<#-- populate customer device id -->
        var io_bbout_element_id = 'customerDeviceIdReferenceCode'; 
        //<#-- do not install Flash        -->
        var io_install_flash = false;  
        //<#-- do not install Active X     -->
        var io_install_stm = false; 
        //<#-- do not run Active X         -->
        var io_exclude_stm = 12;   
        //<#-- enable detection of real IP -->
        var io_enable_rip = true;                               
        (function () {
            var asyncSnareScript = function() {
                var element = document.createElement('script');
                element.src = "https://ci-mpsnare.iovation.com/snare.js";
                document.body.appendChild(element);    
            };
            if (window.addEventListener) {
                window.addEventListener('load', asyncSnareScript, false);
            } else if (window.attachEvent) {
                window.attachEvent('onload', asyncSnareScript);
            } else {
                //<#-- If all else fails, just append the script immediately. -->
                asyncSnareScript();
            }
            //alert('2');
        })();

</script>

我想将相同的代码移动到MVC应用程序。在将代码移动到MVC后,我在视图中删除了表单标签。但现在我没有得到隐藏字段customerDeviceIdReferenceCode的值在页面源。请建议我如何在MVC进行。

中的MVC customerDeviceIdReferenceCode将可能是您的模型上的属性。所以使用剃刀@html.HiddenFor(x => x.customerDeviceIdReferenceCode)