I have a Main View, and 2 Partial Views.
1 Partial View has:
2nd Partial View has:
The functionality I am trying to achieve, when a Click Event
occurs on Add Button
, the data within DropDownList
and TextBox
should appear within the 2nd partial view TextBoxes
(In addition the amount of TextBoxes
is dependent on how many Clicks
the Add Button
received). I'm currently confused on how I can pass the data and preserve it.
Here is the code below, for the first partial view (including a DropDownList
and 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"/>
<% } %>
After user has inserted needed services, All the textboxes values which are in 2nd partial view must be insert into database. My problem is that I must maintain all values but without inserting data into DB. It'll be inserted after use clicks Done button.(I can use table also in second partial view, but that table's value must be available to insert in DB.)
1 Try render action instead of render partial view.
If the values from the DropDown and the Textbox have to save in the DB first that means you have to submit the data first.
So the action would go and fetch the required data from the DB to render the second partial view and return it.
see render action: 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}) %>
<% } %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.