MVC 3 getting values from AppSettings in web.config

Usually I’m using AppSettings static class to access those parameters. Something like this: public static class AppSettings { public static string ClientSecret { get { return Setting<string>(“ClientSecret”); } } private static T Setting<T>(string name) { string value = ConfigurationManager.AppSettings[name]; if (value == null) { throw new Exception(String.Format(“Could not find setting ‘{0}’,”, name)); } return (T)Convert.ChangeType(value, … Read more

Use Html.RadioButtonFor and Html.LabelFor for the same Model but different values

Don’t over-engineer a solution for this. All you are trying to accomplish is to have the radio buttons respond to clicks on the text. Keep it simple and just wrap your radio buttons in label tags: <table> <tr> <td><label>@Html.RadioButtonFor(i => i.Value, “1”)True</label></td> </tr> <tr> <td><label>@Html.RadioButtonFor(i => i.Value, “0”)False</label></td> </tr> </table> The LabelFor html helper is … Read more

Parser Error: Server Error in ‘/’ Application

Right-click your Global.asax file and click View Markup. You will see the attribute Inherits=”nadeem.MvcApplication”. This means that your Global.asax file is trying to inherit from the type nadeem.MvcApplication. Now double click your Global.asax file and see what the class name specified in your Global.asax.cs file is. It should look something like this: namespace nadeem { … Read more

Deploying ASP.NET MVC4 App to GoDaddy Compiler issue

I have struggled with the same problem for months. And finally solved it. In the plesk on godaddy I changed the ASP.Net settings. First changed CAS-trustlevel to Full. Then I changed in the Web.config of my project the following: Add trust level full to the system.web Remove the compilers in the system.codecom <system.web> compilation debug=”true” … Read more

Unobtrusive Ajax stopped working after update jQuery to 1.9.0

Update: This issue has been fixed in the latest NuGet package. I’ve posted another answer to reflect this. https://stackoverflow.com/a/15539422/714309 In jquery.unobtrusive-ajax.js, find and replace these four lines: $(“a[data-ajax=true]”).live(“click”, function (evt) { $(document).on(“click”, “a[data-ajax=true]”, function (evt) { $(“form[data-ajax=true] input[type=image]”).live(“click”, function (evt) { $(document).on(“click”, “form[data-ajax=true] input[type=image]”, function (evt) { $(“form[data-ajax=true] :submit”).live(“click”, function (evt) { $(document).on(“click”, “form[data-ajax=true] :submit”, … Read more

What’s the difference between implementing FilterAttribute, IActionFilter and inheriting from ActionFilterAttribute in asp.net mvc 3?

Basically FilterAttribute provides the most low level behaviour of MVC Attributes and implements the IMvcFilter that provides the Order and AllowMultiple properties. ActionFilterAttribute is the basis for filtering actions and results, since is a implementation of IActionFilter, IResultFilter and inherit from FilterAttribute. Your MySecondFilterAttribute implementation leads to ActionFilterAttribute without IResultFilter capabilities (OnResultExecuting and OnResultExecuted).

404 – A public action method X was not found on controller Y (ActionInvoker.InvokeAction returns false)

The problem is that you’re specifying both the HttpGet and HttpPost attributes. If you leave both of them off, the action accepts both POST and GET requests. My guess is that the HttpGet and HttpPost attributes don’t signal to MVC to allow the corresponding request type, but to deny the opposite type. So by including … Read more

Actionresult vs JSONresult

ActionResult is an abstract class that an action can return. The helper methods in Controller (eg, Json(), Content(), View(), …) return different concrete classes that inherit ActionResult, including JsonResult. You should declare your action methods as returning ActionResult, so that they have the freedom to return any concrete result class.