部分ビューのネストについて説明している前の2つの質問を知っていますが、解決策が私のデザインでは機能しません(これは最良の方法ではないかもしれませんが、どのように適応させるかわかりません)。
背景:
ユーザーからアンケートの回答を収集し、それらをxmlファイルとしてSQLサーバーに保存します。
特定のユーザーのすべての回答を含むテーブルをロードする部分ビューがあります。この部分ビューには、回答日、xml応答ドキュメントへのリンク、質問表名、xml質問票ドキュメントへのリンクなどがテーブルに入力されます(質問票情報はから取得されます)別のテーブル)と、2つの関連するxmlドキュメントを解析して2番目の部分ビュー内に質問と回答のリストを出力する(つまり、応答を人間が読めるように視覚化する)アクションにリダイレクトするAjaxActionLink。
最初の部分ビューには、テーブルの下にdivが含まれており、Ajax.ActionLinkのクリック時に2番目の部分ビューを入力します。
問題:
回答は正しくレンダリングされますが、部分的なビューはスタイル設定なしでまったく新しいページに読み込まれます。
この入れ子の問題に対する他の解決策はRenderPartial()を使用しますが、私はreturn 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");
}
助けていただければ幸いです!