当前位置: 代码迷 >> ASP.NET >> MVC3 Create页面中动态增加一行 怎么进行数据验证
  详细解决方案

MVC3 Create页面中动态增加一行 怎么进行数据验证

热度:8533   发布时间:2013-02-25 00:00:00.0
MVC3 Create页面中动态增加一行 如何进行数据验证?
在MVC3中,动态增加了一行,用以创建数据项下的关联数据(如company下的account项)
而新增的account项对应的编辑行是用jquery通过字符串拼接产生的,假设不填写account项,当submit提交的时候,后台验证不通过,那么会刷新原来界面,从而导致新增的行消失。请问如何前段验证?

C# code
public JsonResult AddAccountInfo(int rowNum)        {            var results = "<tr class='AddedRow' name='AddedRowname'>" +                "<td><input class='text-box single-line' data-val='true' data-val-required='*' id='addAccountInfo_" + rowNum + "__AccountName' name='AccountInfos[" + rowNum + "].AccountName' type='text' value='' /><span class='field-validation-valid' data-valmsg-for='AccountInfos[" + rowNum + "].AccountName' data-valmsg-replace='true'></span></td>" +                "<td><input class='text-box single-line' data-val='true' data-val-required='*' id='addAccountInfo_" + rowNum + "__TaxNumber' name='AccountInfos[" + rowNum + "].TaxNumber' type='text' value='' /><span class='field-validation-valid' data-valmsg-for='AccountInfos[" + rowNum + "].TaxNumber' data-valmsg-replace='true'></span></td>" +                "<td><input class='text-box single-line' data-val='true' data-val-required='*' id='addAccountInfo_" + rowNum + "__Address' name='AccountInfos[" + rowNum + "].Address' type='text' value='' /><span class='field-validation-valid' data-valmsg-for='AccountInfos[" + rowNum + "].Address' data-valmsg-replace='true'></span></td>" +                "<td><input class='text-box single-line' data-val='true' data-val-required='*' id='addAccountInfo_" + rowNum + "__Telephone' name='AccountInfos[" + rowNum + "].Telephone' type='text' value='' /><span class='field-validation-valid' data-valmsg-for='AccountInfos[" + rowNum + "].Telephone' data-valmsg-replace='true'></span></td>" +                "<td><input class='text-box single-line' data-val='true' data-val-required='*' id='addAccountInfo_" + rowNum + "__Account' name='AccountInfos[" + rowNum + "].Account' type='text' value='' /><span class='field-validation-valid' data-valmsg-for='AccountInfos[" + rowNum + "].Account' data-valmsg-replace='true'></span></td>" +                "<td><input class='text-box single-line' data-val='true' data-val-required='*' id='addAccountInfo_" + rowNum + "__Bank' name='AccountInfos[" + rowNum + "].Bank' type='text' value='' /><span class='field-validation-valid' data-valmsg-for='AccountInfos[" + rowNum + "].Bank' data-valmsg-replace='true'></span></td>" +                "<td></td>" +                "</tr>";            return Json(results, JsonRequestBehavior.AllowGet); ;        }

  相关解决方案