1

I am using AngularJS for data binding and I am trying to validate data using HTML5 validation features. It is not working though. Below given is my code:

@using (Html.BeginForm("Ask", "Question", null, FormMethod.Post, new { @id = "myForm", @name = "myForm" }))
{
    <div id="divQuestionTitle">
        <label>Title</label>
        <input name="Title" type="text" ng-model="Title" required />
        {{myForm.Title.$valid}}            
    </div>
    <div id="divQuestionBody">
    </div>
    <div id="divQuestionTags">
        @Html.LabelFor(model => model.Tags)
        <ul id="singleFieldTags"></ul>
        @Html.ValidationMessageFor(model => model.Tags)
    </div>
    <div id="divQuestionSubmit">
        <input type="submit" id="submit" value="Post Your Question" name="submit"/>
    </div>
}

It always displays {{myForm.Title.$valid}} on the page.
Please let me know where I am making mistake.

3
  • check ng-app attribute. angularjs seems to have not been bootsrapped Commented Nov 9, 2016 at 7:38
  • It is loading. I am getting this error in chrome : Uncaught SyntaxError: Unexpected token u in JSON at position 0 at Function.parse [as parseJSON] (<anonymous>) at HTMLFormElement.l (localhost:49910/Scripts/…) at a.validator.e (localhost:49910/Scripts/jquery-3.1.0.min.js:2:3655) Commented Nov 9, 2016 at 8:25
  • Can you paste a url where we can test the web page directly? Commented Nov 10, 2016 at 9:20

1 Answer 1

1

I found the answer here. In short, data-ng-model directive has to be used in place of ng-model if validation is required to be performed.

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.