<div class="container well"> <div class="well"> <form id="productAjaxform" method="get" action='/Learn/GetJsonProducts'> <input type="submit" value="Get" class="btn btn-success" /> </form> </div> <script id="producttemplate" type="text/html"> <div> {{#p}} <p><strong>Name: </strong> {{Name}}</p> <p><strong>Product Category: </strong>{{Category}}</p> <p><strong> Price: </strong> Rs.{{Price}}</p> {{/p}} </div> </script> <div class="well"> <div id="s"> <img id="ajax-loader" src="~/Content/Images/loading.gif" height="60" style="display:none" /> </div> </div>
$("#productAjaxform").submit(function (event) { event.preventDefault(); var form = $(this); $.ajax({ url: form.attr("action"), data: form.serialize(), beforeSend: function () { $("#ajax-loader").show(); }, complete: function () { $("#ajax-loader").hide(); }, error: searchFailed, success: function (data) { var html = Mustache.to_html($("#producttemplate").html(), { p: data }); $("#s").empty().append(html); } }); }); function searchFailed() { $("#searchresults").empty().append("<h4>NO Products Found!!</h4>");
" $('#load').load('/Htmls/Index.html');"+ " function GetProductsJson() {"+ " $.ajax({"+ " url: '/Learn/GetJsonProducts',"+ " data: { id: 1 },"+ "success:"+ " function (result) {"+ " $('#Title').text(result[0].Name);"+ "$('#Description').text(result[0].Category);"+ " $('#CurrentPrice').text(result[0].Price);"+ " } }); }
@model IEnumerablet<string> @Html.ActionLink("Learn Something", "Index", "Learn", null, new { @class = "btn btn-block btn-default btn-sm", @style = "padding:5px" }) @foreach (var link in Model) { @Html.RouteLink(link, new { controller = "Learn", action = "Index", page = link, }, new { @class = "btn btn-block btn-default btn-sm" + (link == ViewBag.Selectedmenu ? " btn-primary" : ""), @style = "padding:10px" }) }
private static List<string> GetMenuItems() { Type myType = (typeof(LearnController)); MethodInfo[] MethodInfoArray = myType .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var v=MethodInfoArray.Where(a=>a.ReturnType==typeof(ActionResult)).Select(a => a.Name); return v.ToList(); } public PartialViewResult Menu(string selectedmenu = null) { ViewBag.Selectedmenu = selectedmenu; Listt<string> menus = new Listt<string>(); menus = GetMenuItems(); return PartialView(menus); }
<form id="productjsonform" method="get" action='/Learn/GetJsonProducts'> <input type="submit" value="Get Json" class="btn btn-success" /> </form> <script id="pt" type="text/html"> <ul> {{#products}} <li>{{Name}}</li> <li>{{Category}}</li> <li>{{Price}}</li> {{/products}} </ul> </script> <div id="s"> </div>
$("#productjsonform").submit(function (event) { event.preventDefault(); var form = $(this); $.getJSON(form.attr("action"), form.serialize(), function (data) { var html = Mustache.to_html($("#pt").html(), { products: data }); $("#s").empty().append(html); }); });
$("*") Selects all elements $(this) Selects the current HTML element $("p.intro") Selects all <p> elements with class="intro" $("p:first") Selects the first <p> element $("ul li:first") Selects the first <li>element of the first <ul> $("ul li:first-child") Selects the first <li> element of every <ul> $("[href]") Selects all elements with an href attribute $("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank" $("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank" $(":button") Selects all <button>elements and <input> elements of type="button" $("tr:even") Selects all even <tr> elements $("tr:odd") Selects all odd <tr> elements