Compiler Error Message: CS1973

I came across this error when I was trying to use the @Render method to render a view while passing through a object that will act as the model for that view.

Compiler Error Message: CS1973: ‘System.Web.Mvc.HtmlHelper’ has no applicable method named ‘Render’ but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

The issue was that the compiler could not choose the correct method because my model was “dynamic”.

The correct syntax is:

1
@Html.Partial("_MyList",(MyClass)myObject)

Disabling Request Validation with ASP.NET MVC

Sometimes when dealing with POSTS and form data, you need to disable Request Validation to allow HTML/scripting data into your methods.   Traditionally with Web Forms you use <%@ Page ValidateRequest=”false” %> which turns off Request Validation, just be aware that this doesn’t work with ASP.NET MVC.

You apply the [ValidateInput] attribute to the controller action in order to make this happen.

1
2
3
4
5
6
7
8
9
[ValidateInput(false)]

[AcceptVerbs(HttpVerbs.Post)]

public ActionResult Create([Bind(Exclude="Id")]Product productToCreate)

{

}