MVC: Check if controller action is called from View or Json
public ActionResult Foo(){ if (Request.IsAjaxRequest() || ControllerContext.IsChildAction) { return PartialView(); } return View(); }
public ActionResult Foo(){ if (Request.IsAjaxRequest() || ControllerContext.IsChildAction) { return PartialView(); } return View(); }
This is an annoying bug and can catch you out at times. If using the Html.DropDownList() helper and the string id you specify has a property on the model or in the ViewBag that matches, you will use your selection….Continue Reading →
MVC’s separation is fantastic but some times you have areas that need to use a common controller. This is a question I see often asked online. If you have a common model that is used in different areas like a…Continue Reading →
Just a quick not on how to pass and render HtmlAttributes in a helper: public HtmlString Add(YourObject yourObject, object htmlAttributes = null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); //process you markup etc. attributes.ToHtmlAttributes() } public static class RouteValueDictionaryExtensions { public static…Continue Reading →