开发者

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

  1. Create a new MVC 3 project
  2. Add the "System.Speech" reference
  3. 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:

MVC View and the System.Speech.Synthesis namespace

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜