MVC没有codebehind强类型的viewdata标题不工作 [英] mvc no codebehind strongly typed viewdata headers not working

查看:124
本文介绍了MVC没有codebehind强类型的viewdata标题不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将它添加到我的标题<%@ Page Language =C#MasterPageFile =〜/ Views / Shared / Site.MasterInherits =System.Web.Mvc.ViewPage% > ,并且能够访问ViewData及其所有内部以及所有mvc对象,如url和html。只要我添加 System.Web.Mvc.ViewPage< app.Models.tTable> 我无法访问任何mvc类和辅助方法。我很困惑这是为什么。我最近从mvc preview 5升级到rc1,但是我向rc1的过渡是完美的,没有任何错误或错误。

捕鱼后(很多钓鱼)我找到了答案,这是因为我没有阅读官方发布说明,而是通过博客中的一个教程,但任何人为了得到这个工作,你需要替换使用

 在您的/ Views目录下的web.config文件中的< pages>  <! -  
在视图页面中启用请求验证将导致验证在控制器已经处理输入后发生
。默认情况下
MVC在控制器处理输入之前执行请求验证。
要更改此行为,请将ValidateInputAttribute应用于
控制器或操作。
- >
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>
<控制>
< add assembly =System.Web.Mvc,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35namespace =System.Web.MvctagPrefix =mvc/>
< / controls>
< / pages>

我从预先构建的web.config文件添加了评论


I add that to my header <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> and am able to access ViewData and all its internals as well as all the mvc objects like url and html. As soon as I add "System.Web.Mvc.ViewPage<app.Models.tTable>" I have no access to any mvc classes and helper methods. I am confused on why this is. I have done an upgrade from mvc preview 5 to rc1 recently but my transition to rc1 was flawless without any errors or bugs.

解决方案

After fishing (alot of fishing) around I found the answer, this is because I didn't read the official release notes rather ran through a tutorial from a blog but anywho to get this working you need to replace the <pages> node in the web.config file in your "/Views" directory with

<!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <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 added the commenting from a pre built web.config file

这篇关于MVC没有codebehind强类型的viewdata标题不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆