- jQuery + JSON Action Methods = Cool
It is easy to return a JSON object instead of a view.public JsonResult Create(string CategoryName) { var category = new Models.Category(); category.Name = CategoryName; category.URLName = CategoryName.ToLower().Replace(" ", "-"); categoryRepository.Add(category); categoryRepository.Save(); return Json(category); }
<script class="str" type="<span"> "text/javascript" language="javascript"> $("#CreateNewCategory").click(function() { $.getJSON("/category/create/", { "CategoryName": $("#NewCategoryName").val() }, CategoryAdded); }); function CategoryAdded(category) { $("#CategoryList").append("
- + category.URLName + "/cat\">" + category.Name + "
"); } </script>
This blog is for .NET and related web technology, where you will find some really good and time saving answers which can help you to make your fundaas clear.
Monday, May 14, 2012
Using jQuery and JSON Action methods in MVC
Labels:
jQuery with MVC,
MVC Tips,
MVC3
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment