如何仅在ASP MVC中回发编辑的行

时间:2015-05-28 04:06:01

标签: c# asp.net-mvc

我有两个模型,如下所示

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="provider_diagnosis_dtls.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="m.provider_diagnosis_dtls.Index" value="@i" /> 
  </td>
  </tr>
    }
    </table>
    }

单击按钮时动态添加到表diagnosis的行。 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());

 });

并且行正在创建,并且在提交数据时传递给控制器​​并且能够保存在数据库中。

现在我必须回复表单中包含所有现有行的已发布详细信息,因为read only表示不允许用户编辑之前创建的现有行,但我们应该允许用户创建按钮上的动态行再次单击。

现在我的疑问是,在提交此编辑表单时,我将如何识别新添加的行,以便我可以仅使用新添加的行更新现有详细信息。

例如:表格中的现有详细信息。

Provider_Preapproval
Preapproval_id     encounter type    e_start_Date e_end_date Status
1                  01                2015-01-01   2015-01-01   s



  diagnosis_dtls

   dtl_id   preapproval_id code       desc      level
   1           1           M01       fever     Primary
   2           1           M2.1      headache  Secondary

此处diagnosis_dtl表格中的每一行都与preapproval ID 1相关。

因此,当我们点击编辑链接时,它将传递预批准ID 1,并将以只读模式检索此详细信息。

现在用户可以动态添加更多行并添加数据,但在提交时,只需要将新添加的行提交到详细信息表,其中preapproval id为1。 例如:    用户添加了一个包含以下详细信息的新行

code       desc      level
 Z1        xxxx      secondary

这应该在diagnosis_dec表中,如下所示

detail_id   preapproval_id code       desc      level
     1           1           M01       fever     Primary
     2           1           M2.1      headache  Secondary
     3           1           Z1        xxx       Secondary

dtl_id不一定是3,因为它是自动生成标识列。

我被困在这里。请注意这点。

发布方法签名

public ActionResult Preapprove(provider_preapproval preapprove_dtl)
{

}

0 个答案:

没有答案