編輯
我改變代碼爲您的需求。我還包括jQuery和jQuery UI的最新版本,以使其工作。
完全答案測試。我可以給你洞解決方案,但我不能在這裏上傳任何文件。如果您向我提供上傳地點,我無法爲您提供整個解決方案。
控制器/ HomeController的
using System.Web.Mvc;
namespace Accordion.Controllers
{
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
[HttpGet]
public ActionResult Verify()
{
return PartialView("_Verify");
}
[HttpGet]
public ActionResult Credentials()
{
return PartialView("_Credentials");
}
[HttpGet]
public ActionResult SelectJob()
{
return PartialView("_SelectJob");
}
[HttpGet]
public ActionResult SendApplication()
{
return PartialView("_SendApplication");
}
}
}
查看/主頁/ Index.cshtml
<div id="accordion">
<h3>Verify</h3>
<div>
@Html.Partial("_Verify")
</div>
<h3>Credentials</h3>
<div>
@Html.Partial("_Credentials")
</div>
<h3 class="disabled">SelectJob</h3>
<div class="dynamic-content" data-action="SelectJob"></div>
<h3 class="disabled">SendApplication</h3>
<div class="dynamic-content" data-action="SendApplication"></div>
</div>
<script type="text/javascript">
jQuery(function() {
var $accordion = $('#accordion')
$accordion.accordion({
collapsible: true,
animated: false,
autoHeight: false,
active: false
});
$accordion.on('accordionbeforeactivate', function (event, ui) {
if (ui.newHeader.hasClass('disabled')) {
return false;
};
});
$accordion.on('accordionactivate', function (event, ui) {
if (ui.newHeader.length > 0
&& ui.newPanel.html().length == 0
&& ui.newPanel.hasClass('dynamic-content') == true) {
var action = ui.newPanel.data('action');
$.ajax({
url: '/Home/' + action,
type: 'GET',
dataType: 'html',
success: function (htmlCodePartialView) {
ui.newPanel.html(htmlCodePartialView);
}
});
};
});
$accordion.on('click', '.next', function() {
var $button = $(this);
var $nextHeader = $button.closest('.ui-accordion-content').next()
$nextHeader.removeClass('disabled').click();
});
});
</script>
查看/主頁/ _Verify.cshtml
This is the view 'Verify'.
查看/主頁/ _Credentials.cshtml
This is the view 'Credentials'.<br />
<button type="button" class="next">Next</button>
查看/主頁/ _SelectJob.cshtml
This is the view 'SelectJob'.<br />
<button type="button" class="next">Next</button>
查看/主頁/ _SendApplication.cshtml
This is the view 'SendApplication'.
瀏覽次數/ _Shared /_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1>My MVC Application</h1>
</div>
<div id="logindisplay">
@Html.Partial("_LogOnPartial")
</div>
<div id="menucontainer">
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
</ul>
</div>
</div>
<div id="main">
@RenderBody()
<div id="footer">
</div>
</div>
</div>
</body>
</html>
解決方案現在看起來是這樣的:
所以basicly你想顯示一個頁面一個頁面?如果是這樣,你可能會需要iframes,不知道是否有其他任何東西替代了這些日子。 –
你需要改變你的動作返回'PartialView()',然後在你定義你的手風琴用戶'@Html的父頁面中。RenderPartial('ActionName')' –
感謝您的快速回復Rory。你能否給我解決一下如何從手風琴的一部分進行交互以展示隱藏的手風琴部分。例如,當用戶在第一部分中單擊按鈕時,顯示第二個手風琴部分?謝謝 – Aqua