【问题标题】:ASP - Master Page and User ControlsASP - 母版页和用户控件
【发布时间】:2018-08-01 04:44:10
【问题描述】:

我目前正尝试在我的母版页中使用 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 似乎是我不时学习的技能之一,所以我从来没有时间真正探索它。

【问题讨论】:

  • 您正在混合使用 Web 表单和 MVC 代码。那是行不通的。选择一种类型并删除错误类型的所有代码。

标签: html asp.net master-pages ascx


【解决方案1】:

@Html 是 Razor 语法。 ASP 需要使用&lt;%&lt;: 等语法。

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

【讨论】:

  • 感谢您,非常感谢。我做了更多的挖掘工作,看起来母版页 Web 表单不适用于 razor 视图,来源:stackoverflow.com/questions/3479094/… 看起来我现在的任务是将其分开并使所有内容符合 mvc 框架:(跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 2017-12-23
  • 2023-04-09
  • 1970-01-01
相关资源
最近更新 更多