/* */

MVC 5 Validation using angular js

@model asdfsdfsdf.Controllers.RolesController.Roles

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Create</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal" ng-controller="actionController">
        <h4>Roles</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { ng_model = "txtCreate", @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="button" value="Create" id="btnCreate()" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">

    function actionController($scope)
    {
        $scope.btnCreate=function()
        {
            if ($scope.txtCreate == null) {
                $.alert('Please provide name'); return false;
            }
        }
    }
 
</script>


Instead if ng-model we will use ng_model and event will fire.
Previous
Next Post »
Thanks for your comment