Throws NullReferenceException when using angularjs with razor .net mvc syntax

I am new to angularjs. I am using angularjs in razor .Net MVC syntax but when I load my page it gives an error which is a Null exception. Below is my code.

@Html.TextBoxFor(model => Model.PlantCode, "PlantCode", 
    new { @class = "form-control", ng_model = "PlantCode", 
        required = "required", ng_pattern = "/^[a-zA-Z0-9_-]+$/", 
        oninvalid = "this.setCustomValidity(' ')",
        data_ng_init = string.Format("PlantCode = '{0}'", Model.PlantCode.Replace("'", @"\'")) }) 

      

When I load the page it gives a Null reference exception, which is Model.PlantCode not set to an object instance. Please help me find a solution. Thanks to

+3


source to share





All Articles