我在模型中具有以下属性:
public class QuoteRequestViewModel
{
public long LeadId { get; set; }
public AgentQuoteInfoModel GeneralInfo { get; set; }
public List<TransportQuoteModel> ListTransport { get; set; }
}
TransportQuoteModel如下:
public class TransportQuoteModel
{
public string InclusionsId { get; set; }
public string ExclusionsId { get; set; }
}
我有一个jquery脚本:
$('.inclusionExclusionMainDiv').each(function (i, obj) {
selectedInclusions = [6-0,8-0];
$("#ListTransport_"+i+"__Inclusions").val(selectedInclusions);
})
在通过javascript提交表单之前,我正在运行上述jquery代码。
cshtml中呈现的InclusionsId和ExclusionsId如下:
<input class="selectedInclusion0" id="ListTransport_0__Inclusions" name="ListTransport[0].Inclusions" type="hidden" value="">
<input class="selectedExclusion0" id="ListTransport_0__Exclusions" name="ListTransport[0].Exclusions" type="hidden" value="">
答案 0 :(得分:0)
您为输入呈现的html格式正确,但它引用的属性名称不存在。
即:您呈现的html应该如下所示:
<input class="selectedInclusion0" id="ListTransport_0__InclusionsId" name="ListTransport[0].InclusionsId" type="hidden" value="">
<input class="selectedExclusion0" id="ListTransport_0__ExclusionsId" name="ListTransport[0].ExclusionsId" type="hidden" value="">
代替:
<input class="selectedInclusion0" id="ListTransport_0__Inclusions" name="ListTransport[0].Inclusions" type="hidden" value="">
<input class="selectedExclusion0" id="ListTransport_0__Exclusions" name="ListTransport[0].Exclusions" type="hidden" value="">
然后您需要适当地更改脚本:
$("#ListTransport_"+i+"__InclusionsId").val(selectedInclusions);