开发者

My Own javascript validation + MicrosoftMvcValidation . Is it possible ? How

I would like to be able to use the MVC validation + my custom javascript validation.

The MVC validation is really nice for Model Validation. The main problem here, is that I have more complexe validation.

Ex: Case with MVC Validation

<div class="editorSmall">
    <div class="editor-label bold">
        <%: Html.LabelFor(model => model.Location.CurID)%>:
    </div>
        <div class="editor-field">
        <%:Html.DropDownListFor(model => model.Location.CurID, Model.CurrenciesList)%>
        <%: Html.ValidationMessageFor(model => model.Location.CurID)%>
    </div>
</div>

<div class="editorSmall">
    <div class="editor-label bold">
        <%: Html.LabelFor(model => model.Location.UnitID)%>:
    </div>
        <div class="editor-field">
        <%:Html.DropDownListFor(开发者_JAVA技巧model => model.Location.UnitID,Model.UnitList)%>
        <%: Html.ValidationMessageFor(model => model.Location.UnitID)%>
    </div>
</div>

As you can see I Use ValidationMessageFor for model validation.

EX: Custom Validation.

Here I want to perform a validation on the listbox. I Want it to be Required. Because this is not strongly typed, I need an other way to make the validation .

 <div class="editorSmall" >
        <div class="editor-label bold">
            <label><%:Model.GrpName1%>:</label>
        </div>
        <div class="editor-field">
             <%: Html.ListBox("Model_Groupe1", new MultiSelectList(Model.Groupe1, "GrpDescID", "GrpDescTxt", Model.Groupe1Selected.Select(g => g.GrpDescID)), new { @class = "grplb" })%>
        </div>
    </div>

What i want : If I click on the Submit Button, I want the built in MVC Validation + my custom validation at the same time... What I Mean is, if the First Validation(MVC one) is invalid, I want my custom validaiton perform his validation too.

Thanks


Could think of a couple of diffrent ways to handle this but, as you probably already have thought of, your custom script validation will not run if script is not enabled on the client. I'm guessing that's not a problem?

In that case: Override submitbutton and do your validation logic before submit. Put the result in hidden input. Add the hidden input to the model and validate that instead of the select.

You could then use the validationmessage for your hidden input to display errors or run the logic again after postback (if you have want your script to display the validationmessages).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜