- 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.
Showing posts with label jQuery with MVC. Show all posts
Showing posts with label jQuery with MVC. Show all posts
Monday, May 14, 2012
Using jQuery and JSON Action methods in MVC
Sunday, May 13, 2012
How to call javascript function on the change of Dropdown List in ASP.NET MVC?
How to call javascript function on the change of Dropdown List in ASP.NET MVC?
Create a java-script function:
Create a java-script function:
Call the function:
<%:Html.DropDownListFor(x => x.SelectedProduct,newSelectList(Model.Products,"Value","Text"),"Please Select a product",new{ id ="dropDown1",onchange="selectedIndexChanged()"})%>
Subscribe to:
Comments (Atom)
