How to read the values returned by the Json?
- by user281180
I have the following code in my view:
<% using (Ajax.BeginForm("JsonCreate", new AjaxOptions { OnComplete = "createCategoryComplete" }))
{ %
Add new category
<%=Html.TextBox("CategoryId")%
<%=Html.TextBox("Test")%
Name:
<%= Html.TextBox("Name")%
<%= Html.ValidationMessage("Name")%
</p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
</div>
<% } %
In the controller the code is as follows:
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult JsonCreate(string Name)
{
if (ModelState.IsValid)
{
try
{
//Return a json object to the javascript
return Json(new { CategoryId = 123, Test= "test successful" });
}
catch
{
#region Log errors about the exception
//Log error to administrator here
#endregion
}
}
//If we got this far, something failed, return an empty json object
return Json(new { /* Empty object */ });
}
What should be the code in the view for the following function to read the values returned by the Json and update the textboxes for CategoryId and Test?
function createCategoryComplete() {....???}