I have this code
if ($("#ProgramMode").val() == "Edit")
{
alert("@ViewBag.ProgramMode");
@**@obj.dataModel = {
data: JSON.parse("@Model.ClientDeds".replace(/"/g, '"')),
location: "remote",
sorting: "local",
sortIndx: "ReferralTypeID",
sortDir: "down"
};
}
When the $("#ProgramMode").val() is evaluated to "Edit" it all works good , as "@Model.ClientDeds" is not null.
However when $("#ProgramMode").val() is evaluated to "Add" , the statement :
JSON.parse("@Model.ClientDeds".replace(/"/g, '"'))
Throws a NullReferenceException since "@Model" is null. if I remove the statement
JSON.parse("@Model.ClientDeds".replace(/"/g, '"'))
and replace it by [] or NUll. it works
This should not be happening,as the if statement is evaluated to false, but it seems that the interpreter checks the value of the elements returned by the server, right? what is the solution?
I checked that the if statement is correctly evaluated in the inspector.
NOTE : I solved it by updating the Create() action method, and change the returning type from :
return view()
to
return view ("Create",new MyObject());
but still need to know why it parse it, inside the if event if it is false