gpt4 book ai didi

c# - 名称 'html' 也不存在于用户控件 MVC 和 C# 的当前上下文中的名称 'model'

转载 作者:行者123 更新时间:2023-12-03 03:22:41 24 4
gpt4 key购买 nike

我正在使用 Microsoft MVC 和 C#。我创建了一个用户控件(example.ascx),在顶部我继承了 System.Web.MVC.ViewUserControl<PostTransferViewModel>

现在,当我的模型名称附加到 ViewUserControl 时,我得到“当前上下文中不存在名称‘Model’”和“当前上下文中不存在名称‘Html’。如果我删除了 <PostTransferViewModel>从 ViewUserControl 的末尾开始,一切正常,但我需要 <PostTransferViewModel>

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PostTransferViewModel>" %>

<div class="postTransferTank">
<h2>
Approved Post Transfers</h2>
<% if (Model.ApprovedPostTransfers.Count() == 0)
{ %>
<span class="emptyList">There are currently no approved Post Transfers for this tank.</span><br />
<% } %>
<% else
{ %>
<%=Html.DisplayFor(x => x.ApprovedPostTransfers,"PostTransferList") %>
<% } %>
<br />
<%=Html.ActionLink<PostTransferController>(x => x.NewPostTransfer(), "Enter Post Transfer", new { @class = "create-link" })%>
<br />
<% if (Model.DraftPostTransfers.Count() != 0)
{ %>
<h2>
Draft Post Transfers</h2>
<%=Html.DisplayFor(x => x.DraftPostTransfers, "PostTransferList") %>
<% } %>
</div>

最佳答案

此论坛帖子有 potential solution to your problem :

Sometimes Intellisense doesn't show up in aspx/ascx/master files if there is a compilation error in the application. If you try running the site and you get a compilation error from ASP.NET, try fixing it and then see if it works.

If the app was previously using ASP.NET MVC Beta and you later changed it to use the fully released version then it's also quite likely that there's a configuration problem. Try comparing the two web.config files in the project (one in the root and one in the Views folder) and see if there are any differences between them.

关于c# - 名称 'html' 也不存在于用户控件 MVC 和 C# 的当前上下文中的名称 'model',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2326312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com