I'm using this Code to make a row template to be added to my table from Jquery I can add it without any problem else the validation Message does'nt displayed

    <script type="text/template" id="template">
        <td>
            @Html.EditorFor(model => item.Quantity, new { htmlAttributes = new { @class = "Q form-control"} })
            @Html.ValidationMessageFor(model => item.Quantity)
        </td>
        <td>
            @Html.EditorFor(model => item.SingleCost, new { htmlAttributes = new { @class = "S form-control"} })
            @Html.ValidationMessageFor(model => item.SingleCost)
        </td>
</script>

in my Java script i use this

function Addrow(){
    var newClass = "newrow"+x;
    var tablerow = '<tr class="Calculated ' + newClass + '">';
    tablerow += $('#template').html();
    tablerow += '</tr>';

    $('#tb').append(tablerow);}

I got output like this

    <input class="S form-control text-box single-line valid" data-val="true"
    data-val-number="The field single_cost must be a number." data-val-required="thisFieldIsReq"      id="item_SingleCost" name="item.SingleCost"  value="0.00" type="text">
    <span class="field-validation-valid" data-valmsg-for="item.SingleCost" data-valmsg-replace="true"></span>

the validation message doesn't displayed when I submit my form

Note: when i use this code without template and directly without Javascript Fuction all thing is OK and validation Message appear

thank you :)

Related posts

Recent Viewed