【问题标题】:pass param to RenderPartial将参数传递给 RenderPartial
【发布时间】:2012-01-15 12:29:21
【问题描述】:

我有 asp.net mvc 2 网站。 有一页为:

   <div id="sidebar">
        <div id="navcontainer">
            <h2>
                Items:</h2>
            <ul id="navlist">
                <li id="active"><a href="#" id="current">item1</a></li>
                <li><a href="#">item2</a></li>
                <li><a href="#">item3</a></li>
                <li><a href="#">Item four</a></li>
                <li><a href="#">Item five</a></li>
            </ul>
        </div>
    </div>
    <div class="article">
        <%Html.RenderPartial("item1");%>
    </div>

我的部分视图(我所有的部分视图都包含静态 html 数据):

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


<h1>
    Lorem</h1>
<p>
    In publishing and graphic design, lorem ipsum[p][1] is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.
</p>

和控制器:

public class InfoController:Controller
{
        private DataManager _dataManager;
        public RegionsController(DataManager dataManager)
        {
            this._dataManager = dataManager;

        }

        public ActionResult info()
        {
            return View(); ;
        }
}

我想实现,当用户点击列表项时,该项必须作为 RenderPartial 的参数传递。如何做到这一点?

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-2 c#-4.0 asp.net-4.0


    【解决方案1】:

    编译页面时会执行Html.RenderPartial 方法。这发生在服务器上。您要求的是客户端的 html 操作。您可以通过使用对 actionresult 方法的 ajax 调用来处理此问题,该方法返回您可以指向文章 div 的部分页面。这可能会有所帮助:

    Walkthrough: Adding AJAX Call

    【讨论】:

      【解决方案2】:

      您可以使用 Ajax 动态更新 &lt;div class="article"&gt; 中的内容。有关如何使用 ajax 加载部分视图的更多信息,请查看以下资源:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-27
        • 1970-01-01
        • 1970-01-01
        • 2013-01-27
        • 2013-11-19
        相关资源
        最近更新 更多