English 中文(简体)
Asp.Net MVC - Problem returning a model to the view
原标题:

I ve recently started using the Areas functionality of the Preview2 and it was working ok until I needed to return a Model to the view.

Controller:

public ActionResult ForgotPassword()
{
   return View(new PasswordViewModel());
}

View:

<%@ Import Namespace="Portal.Site.Areas.Logon.ViewModel"%>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PasswordViewModel>" %>

Nothing to difficult here, except i consistently get the following error.

Parser Error Message: Could not load type  System.Web.Mvc.ViewPage<PasswordViewModel> .

This seems to happen to any view/controller within the areas section. If I remove the return model and add use the Dictionary, it works fine.

Now I am aware of issues regarding this, as the thread describes.

http://forums.asp.net/t/1378448.aspx

I would be interested to see if anyone thinks this is areas related? (Although in a clean basic project this works). Any suggestions on solutions? Is this a bug?

最佳回答

This can be caused by not having a web.config in your views folder.

Example web.config pages settings:

<pages
    validateRequest="false"
    pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=************"
    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=************">
    <controls>
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
    </controls>
</pages>
问题回答

The problem might also be that it can t find the class PasswordViewModel because of a namespace difference. If you are using the default MVC project setup and the PasswordViewModel is in the Model folder, I believe the class name referenced in the page header should be web.model.PasswordViewModel.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签