如何通过传递参数使用 Jquery UI Tab 加载部分视图?

发布于 2024-11-16 12:26:41 字数 2832 浏览 2 评论 0原文

我有一个父页面 (DistributionReview.aspx),其中有一个存款日期,可以使用 DatePicker 选择。

就在下面,我有两个选项卡(*DistributionByType* 和 DistibutionByStatus),我想加载 PartialViews。 这里 PartialView 的参数是 DepositDate

我有一个父页面正在实现的名为 DistributionReviewModel 的自定义 ViewModel。

我遇到直接加载静态部分视图的文章(例如:

如果有人可以共享代码示例以传递参数并在 TabSelection 更改和 DepositDate 更改时加载分部视图,我们将不胜感激。

感谢您抽出时间。

HTML 代码:

<script type="text/javascript">

$(function () {
    //tab
    $("#divDistributionReview").tabs();

    $("#fileDepositDate").datepicker(); //DateTime Picker
    var depositDate = $("#fileDepositDate").val();

});

<div id="container" >

<% using (Html.BeginForm("frmDistributionReview", "DistibutionReview"))
{ %>

    <div> Select a Date: &nbsp;     <input type="text" id="fileDepositDate" name="datepicker"  value='<%= ViewData["FileDepositDate"] %>' /></div>     
    <div id="divDistributionReview">             
    <ul>                 
    <li><a href="/DistributionReview/DistributionByType">Distribution Type</a></li>                 
    <li><a href="/DistributionReview/DistributionByStatus">Status</a></li>             
    </ul>     
    </div> 
        <%} %>
</div>

C# 代码:

public ActionResult DistributionReview()
    {
        ViewData["FileDepositDate"] = DateTime.Now.ToShortDateString();
        var view = View(ApplicationConstants.DistributionReviewViewName, new MegaLockbox.Web.ViewModels.DistributionByTypeViewModel(securityManager, distributionReviewDataAdapter, Convert.ToDateTime(ViewData["FileDepositDate"])));
        return view;
    }


    public ActionResult DistributionByType(string id)
    {
        DateTime depositDate;
        var view = new PartialViewResult();
        if (DateTime.TryParse(id , out depositDate))
        {
            view = PartialView(ApplicationConstants.DistributionByTypeViewName, new MegaLockbox.Web.ViewModels.DistributionByTypeViewModel(securityManager, distributionReviewDataAdapter, depositDate));
        }
        return view;
    }

    public ActionResult DistributionByStatus(string id)
    {
        DateTime depositDate;
        var view = new PartialViewResult();
        if(DateTime.TryParse(id, out depositDate) )
        {
            view = PartialView(ApplicationConstants.DistributionByStatusViewName, new MegaLockbox.Web.ViewModels.DistributionByTypeViewModel(securityManager, distributionReviewDataAdapter, depositDate));
        }
        return view;
    }

I have a parent page (DistributionReview.aspx) that has a Deposit Date to select using DatePicker.

Just below I have two tabs(*DistributionByType* and DistibutionByStatus) that I want to load PartialViews. Here the parameter to the PartialView is DepositDate.

And I have a custom ViewModel called DistributionReviewModel that the parent page is implementing.

I am coming across articles that are directly loading static partial views(Ex:
http://www.kevgriffin.com/blog/index.php/2010/02/23/using-jquery-tabs-and-asp-net-mvc-partial-views-for-ajax-goodness/
). But I am looking for any code sample/articles by passing parameter?

Appreciate if anyone can share code samples to pass parameters and load the partialview both when the TabSelection is changed and and DepositDate is changed.

Thanks for your time.

Html Code:

<script type="text/javascript">

$(function () {
    //tab
    $("#divDistributionReview").tabs();

    $("#fileDepositDate").datepicker(); //DateTime Picker
    var depositDate = $("#fileDepositDate").val();

});

<div id="container" >

<% using (Html.BeginForm("frmDistributionReview", "DistibutionReview"))
{ %>

    <div> Select a Date:       <input type="text" id="fileDepositDate" name="datepicker"  value='<%= ViewData["FileDepositDate"] %>' /></div>     
    <div id="divDistributionReview">             
    <ul>                 
    <li><a href="/DistributionReview/DistributionByType">Distribution Type</a></li>                 
    <li><a href="/DistributionReview/DistributionByStatus">Status</a></li>             
    </ul>     
    </div> 
        <%} %>
</div>

C# Code:

public ActionResult DistributionReview()
    {
        ViewData["FileDepositDate"] = DateTime.Now.ToShortDateString();
        var view = View(ApplicationConstants.DistributionReviewViewName, new MegaLockbox.Web.ViewModels.DistributionByTypeViewModel(securityManager, distributionReviewDataAdapter, Convert.ToDateTime(ViewData["FileDepositDate"])));
        return view;
    }


    public ActionResult DistributionByType(string id)
    {
        DateTime depositDate;
        var view = new PartialViewResult();
        if (DateTime.TryParse(id , out depositDate))
        {
            view = PartialView(ApplicationConstants.DistributionByTypeViewName, new MegaLockbox.Web.ViewModels.DistributionByTypeViewModel(securityManager, distributionReviewDataAdapter, depositDate));
        }
        return view;
    }

    public ActionResult DistributionByStatus(string id)
    {
        DateTime depositDate;
        var view = new PartialViewResult();
        if(DateTime.TryParse(id, out depositDate) )
        {
            view = PartialView(ApplicationConstants.DistributionByStatusViewName, new MegaLockbox.Web.ViewModels.DistributionByTypeViewModel(securityManager, distributionReviewDataAdapter, depositDate));
        }
        return view;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丶视觉 2024-11-23 12:26:41

这里有很好的指南如何执行此操作:

http://ericdotnet.wordpress.com/2009/03/17/jquery-ui-tabs-and-aspnet-mvc/

如果您有任何疑问..请告诉我们:)

PS你可以下载示例并使用它

here you have nice guide how to do this:

http://ericdotnet.wordpress.com/2009/03/17/jquery-ui-tabs-and-aspnet-mvc/

if you have any questions.. let us know:)

PS you can download the example, and play with it

输什么也不输骨气 2024-11-23 12:26:41

选项卡标题的 Html

  <li><a onclick="LoadTabData('type')" href="/DistributionReview/DistributionByType">Distribution   Type</a></li>                 
        <li><a onclick="LoadTabData('status')"  href="/DistributionReview/DistributionByStatus">Status</a></li>   

Jquery 函数

function LoadTabData(type){

if(type='type')

       $.post("YourController/DistributionByType", { id:  $("#fileDepositDate").val()},
            function(data) {
               $(#"yourByTypeTabDiv").html(data);
       });

}else{
  $.post("YourController/DistributionByStatus", { id:  $("#fileDepositDate").val()},
            function(data) {
                $(#"yourByStatusTabDiv").html(data);
       });


}

Html for tab headers

  <li><a onclick="LoadTabData('type')" href="/DistributionReview/DistributionByType">Distribution   Type</a></li>                 
        <li><a onclick="LoadTabData('status')"  href="/DistributionReview/DistributionByStatus">Status</a></li>   

Jquery function

function LoadTabData(type){

if(type='type')

       $.post("YourController/DistributionByType", { id:  $("#fileDepositDate").val()},
            function(data) {
               $(#"yourByTypeTabDiv").html(data);
       });

}else{
  $.post("YourController/DistributionByStatus", { id:  $("#fileDepositDate").val()},
            function(data) {
                $(#"yourByStatusTabDiv").html(data);
       });


}
多孤肩上扛 2024-11-23 12:26:41

这也将起作用。

<div id="tabs">
<ul>
    <li><a href="#tab-1">Tab 1</a></li>
    <li><a href="#tab-2">Tab 2</a></li>
    <li><a href="#tab-3">Tab 3</a></li>
</ul>
 <div id="tab-1">
    @Html.Partial("_PartialViewForTab1", Model)
 </div>
 <div id="tab-2">
    @Html.Partial("_PartialViewForTab2", Model)
 </div>
 <div id="tab-3">
    @Html.Partial("_PartialViewForTab3", Model)
 </div>
</div>

Also this will work.

<div id="tabs">
<ul>
    <li><a href="#tab-1">Tab 1</a></li>
    <li><a href="#tab-2">Tab 2</a></li>
    <li><a href="#tab-3">Tab 3</a></li>
</ul>
 <div id="tab-1">
    @Html.Partial("_PartialViewForTab1", Model)
 </div>
 <div id="tab-2">
    @Html.Partial("_PartialViewForTab2", Model)
 </div>
 <div id="tab-3">
    @Html.Partial("_PartialViewForTab3", Model)
 </div>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文