0

this is my Form:

<% using (Html.BeginForm("RepR", "Agence", FormMethod.Post, new { @class = "search_form" })) { %>
            <%: Html.ValidationSummary(true) %>
            <%: Html.Hidden("to", Model.mailc) %>
           <p>
            Sujet : <br />
            <%: Html.TextBox("sub")%> 

            <br />
             Message : <br />
            <%: Html.TextArea("msg")%> 

           </p>
            <input type="submit" value="Envoyer" class="button"/>
            <% } %>     

It works so fine, but I want to add some validation message (I can't use Model because this form is on page where I use an another model). I already tried with this ways but dosn't works

<%: Html.ValidationMessage("sub","Requiered field") %>


any idea here on what i should use?

1 Answer 1

2

you can use partial view and strongly type Model. then call this partial View in main View. it is a simple and efficient

Other solution is add ModelState.AddModelError("Field Name", "Error Message") but this work only server side.

if you want client side Validation you can use JQuery.valid methode

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.