[英]Passing one partialview's data to another partialview
我有一個主視圖和2個部分視圖。
1部分視圖具有:
第二部分視圖具有:
我試圖實現的功能,當在Add Button
上發生Click Event
時, DropDownList
和TextBox
的數據應該出現在第二個局部視圖TextBoxes
(另外TextBoxes
的數量取決於Add Button
收到的Clicks
)。 我目前對如何傳遞數據並保留數據感到困惑。
以下是代碼,用於第一個局部視圖(包括DropDownList
和TextBox
)。
<% using (Html.BeginForm("AddServices", "Controller1", FormMethod.Post, new { id = "form" }))
{%>
<%: Html.ValidationSummary(true) %>
<div class="edit-set">
<label>Nature of Service:</label>
<div class="editor-field">
<%: Html.DropDownList("ddlServiceType", (SelectList)ViewData["ServiceType"] as SelectList, "--Select Nature Of Service--", new { onchange = "FillServiceType();" })%>
<%: Html.HiddenFor(model => model.Id)%>
<label>Comment:</label>
<input type="text" id="comment" />
</div>
<input type="submit" value="+ Add More Service(s)" onclick="InsertService()" name="submitButton"/>
</div><input type="submit" value="Done" name="submitButton"/>
<% } %>
用戶插入所需服務后,必須將第二個局部視圖中的所有文本框值插入到數據庫中。 我的問題是我必須維護所有值但不將數據插入數據庫。 它會在使用后單擊Done按鈕插入。(我也可以在第二個局部視圖中使用表,但該表的值必須可以插入DB中。)
1嘗試渲染操作而不是渲染局部視圖。
如果DropDown和Textbox中的值必須首先保存在DB中,這意味着您必須首先提交數據。
因此,操作將從DB獲取所需數據以呈現第二個局部視圖並將其返回。
請參閱渲染動作: http : //haacked.com/archive/2009/11/17/aspnetmvc2-render-action.aspx
<% using (Html.BeginForm("AddServices", "Controller1", FormMethod.Post, new { id = "form" }))
{%>
<%: Html.ValidationSummary(true) %>
<div class="edit-set">
<label>Nature of Service:</label>
<div class="editor-field">
<%: Html.DropDownList("ddlServiceType", (SelectList)ViewData["ServiceType"] as SelectList, "--Select Nature Of Service--", new { onchange = "FillServiceType();" })%>
<%: Html.HiddenFor(model => model.Id)%>
<label>Comment:</label>
<input type="text" id="comment" />
</div>
<input type="submit" value="+ Add More Service(s)" onclick="InsertService()" name="submitButton"/>
</div><input type="submit" value="Done" name="submitButton"/>
<%= Html.Action("MyAction", "Controller", new {ID = Model.id}) %>
<% } %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.