【发布时间】:2018-08-01 04:44:10
【问题描述】:
我目前正尝试在我的母版页中使用 UserControl;但是我的 ascx 文件不喜欢我的代码,具体分为两部分:
- @Html(当前上下文中不存在)
- 型号。 (当前上下文中不存在)
.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ConveyancingUserControl.ascx.cs" Inherits="xxx.Controllers.ConveyancingUserControl" %>
<div id="cwContainer" class="ui-widget-content">
<div id="cwHead">
<p class="cwhTitle">Conveyancing Quotation</p>
</div>
<div id="cwBody">
<%using (Html.BeginForm("Home", "Xxxx", FormMethod.Post, new { onsubmit = "document.getElementById('xxxxBusy').style.display = 'inline';", @class = "xxxxForm" }))
{%>
<table>
<tr>
<td>What are you doing?</td>
<td> <%: @Html.DropDownListFor(Quote => Model.sessionQuote.quoteType, Model.sessionQuote.quoteTypeList, new { style = "width:150px" })%> </td>
</tr>
</table>
<%} %>
</div>
<div id="cwFoot"></div>
</div>
ascx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mvc;
namespace ASP4HFWClaimsPortal.Controllers
{
public partial class ConveyancingUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
.大师:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<xxx.Models.XxxxSession>" %>
<!-- The main body of each page -->
<div id="MainBody" runat="server" >
<ul class="xxxxMenu">
<li class="xx"> <%: Html.ActionLink("Home", "Home", "x", null, new { onclick="document.getElementById('xx').style.display = 'inline';", @class="x", @title="Home" })%></li>
<li class="x"> <%: Html.ActionLink("About", "About", "Xxxx", null, new { onclick="document.getElementById('xx').style.display = 'inline';", @class="x", @title="About" })%></li>
</ul>
<section class="content-wrapper main-content clear-fix">
<!-- Additional BODY content for each individual page is inserted here -->
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</section>
<uc1:conveyancingusercontrol ID="ConveyancingUserControl1" runat="server" />
</div>
Web.config:
<controls>
<add src="~/Controllers/ConveyancingUserControl.ascx" tagName="ConveyancingUserControl" tagPrefix="uc1"/>
</controls>
我意识到我的 ascx 文件需要某种参考才能找到我的模型我只是不确定如何执行此操作……或者是否可能。关于“HTML”。问题,我想这是类似的。
抱歉,如果这些问题是愚蠢的...... ASP 似乎是我不时学习的技能之一,所以我从来没有时间真正探索它。
【问题讨论】:
-
您正在混合使用 Web 表单和 MVC 代码。那是行不通的。选择一种类型并删除错误类型的所有代码。
标签: html asp.net master-pages ascx