本文介绍了值的隐藏字段设置不是在文件准备功能体现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从隐藏字段检索值。有时候,我得到的值和放大器;有时它的到来为空。请协助。

也让我知道,我们可以存储一个C#的ArrayList在hiddenfield?
我的HTML看起来像这样...

 <输入类型=隐藏ID =hdnSelectedContactIDVALUE =@ Model.Contact.ContactID/>
<输入类型=隐藏ID =hdnSelectedAddressListVALUE =@ Model.Contact.AddressList/>
$(文件)。就绪(函数(){
        _contactID = $(#hdnSelectedContactID)VAL()。
        。_addressList = $(#hdnSelectedAddressList)VAL();
}

在的document.ready方法分配一个名称,它之后,外部HTML(快速腕表)出现这样的...

  outerHTML<输入ID = hdnSelectedContactID类型=隐藏的名称= hdnSelectedContactID>中串outerHTML<输入ID = hdnSelectedAddressList值= Dell.USP.Business.Models.TelephoneList类型=隐藏的名称= hdnSelectedAddressList>中串


解决方案

为什么不使用辅助插入一个隐藏字段?

  @ Html.HiddenFor(H => h.ContactID)

您不能存储在hiddenfield作为一个对象的ArrayList,但你可以在分隔符单独他们hiddenfield插入一个ArrayList的值。你把它变成一个字符串,并在视图中加载它。

I am not able to retrieve the values from hidden field. Sometimes I am getting values & sometimes its coming empty. Please assist.

Also let me know can we store a C# arraylist in a hiddenfield?My HTML looks like this...

<input type="hidden" id="hdnSelectedContactID" value="@Model.Contact.ContactID" />
<input type="hidden" id="hdnSelectedAddressList" value="@Model.Contact.AddressList" />


$(document).ready(function () {
        _contactID = $("#hdnSelectedContactID").val();
        _addressList = $("#hdnSelectedAddressList").val();
}

After assigning a name to it in document.ready method, the outer html(in quick watch) appears like this...

outerHTML         "<INPUT id=hdnSelectedContactID type=hidden name=hdnSelectedContactID>"            String

outerHTML         "<INPUT id=hdnSelectedAddressList value=Dell.USP.Business.Models.TelephoneList type=hidden name=hdnSelectedAddressList>"       String
解决方案

Why not use a helper to insert a hidden field?

@Html.HiddenFor(h => h.ContactID)

You can't store an arraylist in a hiddenfield as an object, but you can insert the values of an arraylist in a hiddenfield with delimiters to seperate them. You turn it into a string and load it in the view.

这篇关于值的隐藏字段设置不是在文件准备功能体现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:05