ASP - 母版页和用户控件

时间:2018-02-21 14:41:41

标签: html asp.net master-pages ascx

我目前正在尝试在母版页中使用UserControl;但是我的ascx文件不喜欢我的代码,具体来说有两个部分:

  1. @Html(当前上下文中不存在)
  2. 模型。 (在当前上下文中不存在)
  3. 的.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:

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

1 个答案:

答案 0 :(得分:1)

@Html是Razor语法。您需要对ASP使用<%<:等语法。

模型存在于MVC中,您需要查看代码隐藏以填充控件。