2015-04-21 25 views
0

我有两个型号如下动态生成的行细节不回发

public partial class provider_preapproval 
{ 
public string encounter_type { get; set; } 
public DateTime? e_start_date { get; set; } 
public DateTime? e_end_date { get; set; } 
public string status { get; set; } 
public virtual IList<provider_diagnosis_dtls> provider_diagnosis_dtls { get; set; } 
} 

public partial class provider_diagnosis_dtls 
{ 
    public string diagnosis_code { get; set; } 
    public string diagnosis_desc { get; set; } 
    public string diagnosis_level { get; set; } 
} 

为同一的观点是

@using (Html.BeginForm("Preapprove", "Preapproval", FormMethod.Post) 
{ 
@Html.LabelFor(model => model.encounter_type, htmlAttributes: new { id = "n", @class = "control-label" })             
@Html.DropDownListFor(model => model.encounter_type, (SelectList)@ViewBag.Encounter, "---Select Encounter Type ---", new { @class = "m-wrap " 
@Html.LabelFor(model => model.status, htmlAttributes: new { id = "n", @class = "control-label" })            @Html.TextBoxFor(model => model.status, new { id = "status", @Value = "New", @readonly = "readonly" }) 
@Html.LabelFor(model => model.e_start_date, htmlAttributes: new { id = "e_start", @class = "control-label " })            @Html.TextBoxFor(model => model.e_start_date, new { id = "start", @class = "m-wrap ", @Value = @TempData["service_date"], @readonly = "readonly" }) 
@Html.LabelFor(model => model.e_end_date, htmlAttributes: new { id = "e_end", @class = "control-label " })            @Html.TextBoxFor(model => model.e_end_date, new { id = "end", @class = "m-wrap datepicker", @Value = @TempData["service_date   

//Template for dynamic generating row       
<table id="Newdiagnosis" style="display:none"> 
<tr> 
<td><input class="diag" style="width:200px" type="text" name="provider_diagnosis_dtls[#].diagnosis_code" value /></td> 
<td><input class="diag_desc" style="width:500px" type="text" name="provider_diagnosis_dtls[#].diagnosis_desc" value /></td> 
<td> 
<input type="text" name="provider_diagnosis_dtls[#].diagnosis_level)" readonly value /> 
<input type="hidden" name="diagnosis.Index" value="%" /> 
</td> 
</tr> 
</table> 
<table id="diagnosis" class="table table-striped table-hover table-bordered"> 
@if (Model != null) 
{ 
for (int i = 0; i < Model.provider_diagnosis_dtls.Count; i++) 
{ 
<tr> 
<td>@Html.TextBoxFor(m => m.provider_diagnosis_dtls[i].diagnosis_code)</td> 
<td>@Html.TextBoxFor(m => m.provider_diagnosis_dtls[i].diagnosis_desc)</td> 
                            @Html.TextBoxFor(m => m.provider_diagnosis_dtls[i].diagnosis_level, new { @Value = "Primary", @readonly = "readonly" })            <input type="hidden" name="diagnosis.Index" value="@i" /> 
              </td> 
             </tr> 
} 
</table> 
} 

现在我能够生成动态行表#diagnosis使用jquery并添加值,但在“Provider_preapproval”模型中发布“provider_diagnosis_dtls”Ilist时会显示null。

enter image description here

比这ILIST其他细节正在到来。

请告诉我在我的代码中有什么问题。

编辑

jQuery的

$(document).ready(function() { 
$("#N").click(function() { 

var index = (new Date()).getTime(); 
var clone = $('#Newdiagnosis').clone(); 
clone.html($(clone).html().replace(/\[#\]/g, '[' + index + ']')); 
clone.html($(clone).html().replace(/"%"/g, '"' + index + '"')); 
var html = clone.html(); 
$("#diagnosis").append(clone.html()); 
       $("#diagnosis").find(".diag").last().tokenInput("@Url.Action("SearchDiagnosis","Preapproval")", 
        { 
         theme: 'facebook', 
         preventDuplicates: true, 
         searchingText: 'Searching...', 
         tokenLimit: 1 
        }); 

     $("#diagnosis").find(".diag_desc").last().tokenInput("@Url.Action("SearchDiagnosis_desc","Preapproval")", 
        { 
         theme: 'facebook', 
         preventDuplicates: true, 
         searchingText: 'Searching...', 
         tokenLimit: 1 
        }); 

        }); 
+0

首先你不是通过jquery为你的模型属性赋值!你可以显示你的jQuery? –

+1

您还需要显示帖子方法签名 –

+0

您好Stephen,公共ActionResult Preapprove(provider_preapproval preapprove_dtl){.......}这是post方法签名.. – Sachu

回答

1

在模板中的索引器隐藏输入的名称有误(不与你的财产相匹配。它需要

<input type="hidden" name="provider_diagnosis_dtls.Index" value="%" /> 

请注意,您还需要在for循环中更改它以及

<tr> 
    <td>@Html.TextBoxFor(m => m.provider_diagnosis_dtls[i].diagnosis_code</td> 
    <td>@Html.TextBoxFor(m => m.provider_diagnosis_dtls[i].diagnosis_desc</td> 
    <td> 
     @Html.TextBoxFor(m => m.provider_diagnosis_dtls[i].diagnosis_level, new { @Value = "Primary", @readonly = "readonly" }) 
     <input type="hidden" name="m.provider_diagnosis_dtls.Index" value="@i" /> // change this 
    </td> 
</tr> 
+0

糟糕!!谢谢斯蒂芬..它现在工作完美:) – Sachu

+0

亲爱的史蒂芬,是否有可能为asdropdownlistfor其中一个文本框,然后我应该如何更改动态隐藏模板。 – Sachu

+0

只需使用'@ Html.DropDownListFor(...)'创建一个'