我知道前面两个问题,它们讨论嵌套部分视图,但解决方案不适用于我的设计(这可能不是最好的,但我是不确定如何调整它)。MVC3嵌套部分视图调用Ajax.ActionLink
背景:
我收集来自用户的问卷答案,并将其存储在SQL Server为XML文件上。
我有一个部分视图,它加载了一个给定用户的所有响应的表格,这个部分视图填充了类似响应日期,xml响应文档的链接,调查问卷名称,xml问卷文档的链接(问卷info从另一个表中拉出来)以及一个Ajax ActionLink,它将重定向到分析两个相关xml文档以在第二个局部视图内打印出问题和答案列表(即将响应可视化为人类可读)的操作。
第一个局部视图在表格下方包含一个div,我希望用第二个局部视图填充Ajax.ActionLink。
问题:
的回答正确呈现然而局部视图被加载到一个全新的页面,而没有任何样式。
其他办法解决这一嵌套问题使用的RenderPartial(),但是我用回PartialView()
代码:
第一部分视图:
<table>
<thead>
<tr><th>headers with other info</th>
<th>Display(/th>
<tr>
</thead>
<tbody>
<tr><td>cells with other info</td>
<td>@Ajax.ActionLink("View", "DisplayResponse","HealthStatus", new { respID = item.UniqueID,qVersion=item.QuestionnaireVersion, qname = item.QuestionnaireName }, new AjaxOptions { UpdateTargetId = "responseDisp" })</td>
</tbody>
</table>
<div id="responseDisp"></div> <--- **This is the div I wish to populate, does anyone know why it's not working?**
DisplayResponse行动(不解析xml文档的逻辑)
public ActionResult DisplayResponse(Guid respID, int qVersion, String qname) {
var allResponses = ZData.Responses;
var response = (from r in allResponses
where r.UniqueID == respID
select r
).First();
//geting an XML questionnaire document
var questionnaireDetails = ZodiacData.Questionnaires;
var questionnaire = (from q in questionnaireDetails
where q.Name == qname && q.Version == qVersion
select q
).First();
//creating XMLDocument to read the questionnaire
XmlDocument xqdoc = new XmlDocument();
xqdoc.LoadXml(questionnaire.Xml);
XmlElement qroot = xqdoc.DocumentElement;
ViewBag.qroot = qroot;
XmlDocument xrdoc = new XmlDocument();
xrdoc.LoadXml(response.Raw);
XmlElement rroot = xrdoc.DocumentElement;
ViewBag.rroot = rroot;
return PartialView("_PrintedResponse");
}
我会很感激任何帮助!
检查'jquery.unobtrusive-ajax.js'文件包含在你的观点,因为这个文件中包含有需要的js函数'@ Ajax.ActionLink' – nemesv 2012-07-20 12:53:01
贵部分有型号?我没有看到你传递任何东西给部分。 – anAgent 2012-07-20 12:57:54
@nemesv:谢谢!就是这样,多么尴尬。如果您想将其作为答案,我会接受它。 – Nieszka 2012-07-20 13:05:00