-1

I am a new in MVC Programming in asp.net.I created application in mvc4 with entity framework.My problem is that i can't validate input entry.It always return true

.My index.aspx code here

<% using (Html.BeginForm("Validate","Transport")){%>
    <table id="tblogin">
      <tr>
        <th style="text-align:right">Email</th>
        <td>
          <%=Html.TextBox("email") %>
          <%= Html.ValidationMessage("email", "*")%>
        </td>
    </tr>
    <tr>
      <th style="text-align:right">Password</th>
      <td>
         <%=Html.TextBox("pswd") %>
         <%= Html.ValidationMessage("pswd", "*")%>
      </td>
    </tr>
    <tr>
       <th></th>
       <td align="right"><input style="" type="submit" value="login" ></td>
    </tr>
  </table>
<%} %>

My model class is

[Required]
public string email { get; set; }
[Required]
public string pswd { get; set; }

debugg image here

  • Not clear what your asking. Show your controller code for the method your posting to. –  May 09 '15 at 11:57
  • Your `ActionResult Validate()` is not receiving any parameters, it should be receiving your view's viewmodel so you can validate it. – zed May 09 '15 at 12:35

1 Answers1

0

Try using..

<%=Html.TextBoxFor(model => model.email,..) %>

instead

<%=Html.TextBox("email") %>

May this helps.

iTechOwl
  • 150
  • 11
  • @BhupeshMhashakhetri, OP means that they got the answer elsewhere. While its always better practice to use the strongly typed helpers, your answer does not make the slightest bit of difference - both produce identical html. –  May 09 '15 at 12:58