ASP - 母版页和用户控件

ASP - Master Page and User Controls

我目前正尝试在我的母版页中使用 UserControl;但是我的 ascx 文件不喜欢我的代码,特别是两部分:

  1. @Html(在当前上下文中不存在)
  2. 型号。 (在当前上下文中不存在)

.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 似乎是我不时跳入的技能之一,所以我没有时间真正探索它。

@Html 是 Razor 语法。您需要对 ASP.

使用 <%<: 等语法

模型存在于 MVC 中,您需要查看 code-behind 来填充您的控件。