简体   繁体   中英

'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' - ASP.Net MVC

I've been trying to run ASP.Net MVC 1.0 on one machine, but can't get past this. I create a new MVC project (C#). It creates all the folders, views, controllers, models etc. All good. Then, when I hit F5, I get the following:

d:\\VSCode2008\\MVC\\MvcApplication1\\Views\\Shared\\Site.Master(19): error CS0117: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial'

this happens at the following line:

httpHandler.ProcessRequest(HttpContext.Current); in Default.aspx.cs

It seems when it is trying to do a RenderPartial() to render the logon partial.

I have version 3.51 of .Net framework installed. I installed version 1.0 of MVC, and the assembly clearly has RenderPartial() as extension methods of HtmlHelper.

Anyone seen anything similar? I have found some posts about similar problems with betas and RCs but the suggested fixes have not woredk.

I am loving the theory of MVC but it is not letting me play!

只是想排除这里明显的问题,但是您能确保在 web.config 的命名空间部分中有这个吗?

<add namespace="System.Web.Mvc.Html"/>

Since you are referencing it in your Code Behind (ie. Default.aspx.cs) you need to include the namespace at the top of the file.

using System.Web.Mvc.Html;

is the Namespace that includes the RenderPartial extension method.

You may think this is dumb, but I just had the same problem. I had a working MVC app, running 1.0.0.0 and all of a sudden it stopped working giving me the same RenderPartial isn't in the definition. Well it turns out that while I was going crazy cleaning up my web.config, I removed this section. When I re-added it, everything worked again. I'm sure this has something to do with how the class extensions load during runtime.

Anyway, re-adding this to my web.config worked on my machine. ;)

<system.codedom>
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                     type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="WarnAsError" value="false"/>
        </compiler>

        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4"
                     type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="OptionInfer" value="true"/>
            <providerOption name="WarnAsError" value="false"/>
        </compiler>
    </compilers>
</system.codedom>

According to your error message, you are referencing System.Web.Mvc.HtmlHelper . I am looking at the System.Web.Mvc dll in Reflector, and it's telling me that RenderPartial resides in the namespace System.Web.Mvc.Html , not System.Web.Mvc.HtmlHelper .

Another possible problem (depending on your error string) is that the extension method is there, but that the compiler couldn't match up your parameters to the known method parameters. I ran into this using T4MVC (noob) and forgetting to add ActionNames before the name of the action I was calling.

我的项目* .sln自2017年以来未更新。请参见此处: 名称“ ViewBag”在当前上下文中不存在-Visual Studio 2015,用于Sonic Soul的修复方法。

If you migrated to visual studio 2017 or 2019 and your project is mvc4, go back into visual studio installer and check the mvc4 option under the "ASP.net and web development".

Solved my issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM