MVC View and the System.Speech.Synthesis namespace - asp.net-mvc

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.

Related

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.

How to develop a simple ASP.NET MVC project without Visual Studio

I have been able to develop a simple asp.net project without vs. Can someone help me doing the same for a asp.net mvc 3. Starting from getting the ASP.NET MVC 3 framework. It seems that we can't download anymore the assemblies. Is it possible to have the project compiled on the fly ( I mean without compiling the my web application but letting IIS doing so , it is possible to achieve this with the regular asp.net so I assume it could be possible with the MVC framework)
Thx
Dave
Sure, it's pretty easy, only a couple of steps after you install ASP.NET MVC 3.
Fire notepad.exe and create a HomeController.cs file (Of course if you don't want to use notepad you could also do this by using the copy con HomeController.cs command on the command prompt, this way you will be closer to the metal):
namespace MyApplication
{
using System.Web.Mvc;
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
Compile on the command prompt (adjust the folders to match yours)
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /t:library /out:MyApplication.dll /r:"C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll" HomeController.cs
Create a folder c:\MyApplication
Create a folder c:\MyApplication\bin and copy MyApplication.dll to this bin folder.
Inside c:\MyApplication\web.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<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>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Inside c:\MyApplication\Views\web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<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.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<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>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
Inside c:\MyApplication\Global.asax:
<%# Application Language="C#" %>
<%# Import Namespace="System.Web.Mvc" %>
<%# Import Namespace="System.Web.Routing" %>
<script runat="server">
static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
</script>
Inside c:\MyApplication\Views\Home\Index.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
Hello Word
</body>
</html>
Now you have all the necessary files for an ASP.NET MVC 3 application. The final step is to host it on a web server and run it.
Conclusion: unless you are suffering from some severe brain damage you will never do this and simply download Visual Studio 2010 Express and start developping ASP.NET MVC 3 applications by following the tutorials on the ASP.NET MVC web site.
Could you give a reason you don't want to use visual studio? There are free versions that are quite capable as IDEs.
If you would prefer to learn in a much more text editor experience you can also use Microsoft WebMatrix to create them on your local computer.
The easiest way to install Webmatrix or Visual Studio Web Developer Express is probably using the Web Platform Installer.

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>

Trouble with MVCContrib InputForm<T> and SparkViewEngine

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.

Resources