Trouble with MVCContrib InputForm<T> and SparkViewEngine - asp.net-mvc

I am trying to use MVCContrib InputBuilders but I am having trouble. I am also using S#arp architecture and spark. My spark view looks like this:
new.spark:
<viewdata model="NewUserViewModel" />
${Html.InputForm<NewUserViewModel>()}
My global.asax.cs contains:
protected void Application_Start() {
XmlConfigurator.Configure();
var controller = InitializeServiceLocator();
ModelBinders.Binders.DefaultBinder = new SharpModelBinder();
ViewEngines.Engines.Clear();
InputBuilder.BootStrap();
ViewEngines.Engines.Add(controller.Resolve<IViewEngine>());
RouteRegistrar.RegisterRoutesTo(RouteTable.Routes);
}

I hate it when I answer my own question but I found adding this to the /Views/Web.config under </system.web> fixed my problem.
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
I'm not really sure why that helped. My guess is my app was configured to only to work with spark views and this is adding the regular view engine back in, but I am not expert here.

Related

ASP.NET MVC 4 Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0,

I have an asp.net mvc 4 project working on VS2010, it was working fine yesterday but I uninstalled VS2012 and the project has now stopped working, it throws the following exception message:
System.IO.FileNotFoundException: Could not load file or assembly
'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
system cannot find the file specified.
I have checked and this is not referenced anywhere in the project, the project uses SignalR, maybe this is a requirement for it?
I have checked the related questions in the site but still cannot make it work
Web.config file under Views folder:
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>
</system.webServer>

customErrors is not wroking in asp.net mvc3

I'm new to ASP.net MVC. I have set customErrors to on in my web.config, and global.ascx.cs containd the following code:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
But when I throw an exception, I still see the yellow page error that shows stack trace. What else should I do? Any help is appreciated in advance.
Edit
Here is part of my web.config content:
<system.web>
<customErrors mode="On"/>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
If what you want to happen is that the application shows the default Error view, your customErrors config should be:
<customErrors mode="On" defaultRedirect="Error" />
If you're trying to achieve something else, please provide details.

MVC View and the System.Speech.Synthesis namespace

This is very strange. An MVC View refuses to recognize the System.Speech namespace. What's the deal? And is there a work around for this? I have a ViewModel that has the VoiceAge and VoiceGender enum properties from this namespace, but the MVC view isn't playing ball.
Repro
Create a new MVC 3 project
Add the "System.Speech" reference
Try to navigate to the System.Speech namespace in the view
In the Controller it's no problem:
using System.Speech.Synthesis;
using System.Web.Mvc;
namespace MvcApplication6.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
VoiceAge voiceAge = VoiceAge.Adult;
return View();
}
}
}
The View, not so much:
I've even added the namespace to the web.config, no luck:
<pages>
<namespaces>
<add namespace="System.Speech.Synthesis" />
Make sure that the System.Speech assembly is present in the <assemblies> section of your web.config:
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
Once it is added there make sure you recompile, close and re-open the .aspx view and then, normally, it should work.

MVC - strongly typed views are broken

So I wrote a custom web control in MVC, and I did the whole csc thing to create a dll out of it.
That didn't work, but when I removed it and everything. My MVC thing broke, and it's giving me this error:
Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage'.
for this line:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<List<className>>" %>
It's not liking strongly typed view now (normal views are working okay)! I'm not registering the dll anywhere anymore. I deleted the dll from bin. I even got rid of the class.
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=gibberish"/>
</assemblies>
</compilation>
Check your web.config for this assembly line under compilation:
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken="gibberish" />
</assemblies>
</compilation>

MvcContrib Portable Areas View Intellisense?

I've started using Portable Areas from the MvcContrib project. Everything works great with the exception of Visual Studio Intellisense. Has anyone been able to get their View intellisense to work...
Html. <-- does not exist in the current context.
I'm also not able to get intellisense on any of the models created in the same project...
I have the following web.config under the View folder for each portable area and intellisense is working for me. This is using asp.net 4.0, but I am pretty sure you can use the same format under 3.5.
Hope this helps
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<pages validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web>
</configuration>
Yes. You need the pages declaration from the web.config in the normal views/shared folder in the folder you have your portable area view:
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter"
pageBaseType="System.Web.Mvc.ViewPage"
userControlBaseType="System.Web.Mvc.ViewUserControl">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
I got this Web.Config from the PrecompiledMvcViewEngine NuGet Package and it works like a charm!
Place it in the root folder of your project!!
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>

Resources