我想问一下,当我使用Ajax.Beginform提交表单时,如何保留我的部分视图...当我提交表单时,我的部分视图消失
这里是代码
@using (Ajax.BeginForm("HardwareProblem", new AjaxOptions { HttpMethod = "Post" }))
{
@Html.AntiForgeryToken()
<div>
<div id="ErroDiv" class="message-error" style="position:absolute;"> </div>
<div id="successDiv" class="message-success" style="position:absolute;"> </div>
<ul class="po_btn_l1">
<li><a href="#" class="btn print">Print Report</a></li>
<li><a href="#" class="btn pop-up">Pop-up Complete List</a></li>
<li><a href="#" class="btn screen-shot">Screen Shot</a></li>
<li>
@Html.TextBox("Search PO_No", "Goto PO #", new { @class = "po_search" })
</li>
</ul>
<ul class="po_btn_l2">
<li><input type="submit" value="Save & Exit" class="btn save-exit"></li>
<li><a href="#" class="btn discard-changes">Discard Changes</a></li>
<li><a href="#" class="btn delete">Delete</a></li>
<li><a href="#" class="btn cancel">Cancle</a></li>
</ul>
</div>
<div class="ca-dbhdng" style="width:96%; height :5px; padding:0px;">
@*<i class="dash-ico-b"></i><h2 style="color: #21355c; font-size:11px;"> Dashboard > Purchase Order</h2>*@
</div>
<fieldset class="fieldset">
<table class="tbl-barcode" style="width: 959px; float: left; padding-bottom: 20PX; ">
<tbody>
<tr>
<td><span class="number">01.</span></td>
<td class="label-text">
<label> GulfIT PO # : </label>
</td>
<td>
@Html.TextBoxFor(model => model.GulfItPO_NO,
new { @class = "text-field-search validate[required]" })
<input type="button" value="Search" id="Get_Po_Data" class="po_searchm" />
@Html.HiddenFor(model => model.PO_ID, new { @type = "hidden", @id = "PO_ID" })
</td>
<td><span>04.</span></td>
<td class="label-text">
<label>Current Laptop Department:</label>
</td>
<td>
@Html.TextBoxFor(model => model.Laptop_PO_Qty, new { @class = "text-field-readonly validate[required]", @readonly = "readonly" })
</td>
</tr>
<tr class="spaceUnder">
<td><span class="number">02.</span></td>
<td class="label-text">
<label> Laptop Serial No: </label>
</td>
<td>
@Html.TextBoxFor(model => model.Laptop_Sr_No,
new { @class = "text-field-search validate[required]" })
<input type="button" value="Search" id="Get_Laptop_SrNO" class="po_searchm" />
@Html.TextBox("PO_ID", "", new { @type = "hidden", @id = "PO_ID" })
</td>
<td><span>05.</span></td>
<td class="label-text">
<label>Shift to Department:</label>
</td>
<td>
<select id="Delivery_Stauts_ID" class="dropdown">
<option>Select</option>
<option>Received</option>
<option>Labchecking</option>
<option>Workshop Repair</option>
<option>Paint Shop</option>
<option>Ready For Sale</option>
<option>Sold</option>
<option>Stor For Parts</option>
<option>Scrap Laptop </option>
</select>
</td>
</tr>
<tr>
<td><span class="number">03.</span></td>
<td class="label-text">
<label> Gulf It BarCode: </label>
</td>
<td>
@Html.TextBoxFor(model => model.Crnt_GulgIt_Barcode,
new { @class = "text-field-search validate[required]" })
<input type="button" value="Search" id="Get_Crnt_Barcode_Data" class="po_searchm" />
@Html.TextBox("PO_ID", "", new { @type = "hidden", @id = "PO_ID" })
</td>
<td colspan="2"> </td>
<td>
<input type="submit" value="Update and Move" class="btn save-exit">
</td>
</tr>
</tbody>
</table>
<div class="ca-dbhdng" style="width:96%; height :5px; padding:0px;">
@*<i class="dash-ico-b"></i><h2 style="color: #21355c; font-size:11px;"> Dashboard > Purchase Order</h2>*@
</div>
<div id="wp-hardware_problem1">
</div>
</fieldset>
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult HardwareProblem(WH_Hardware_Problem_Model REC)
{
/// inserting my partial view form code
return View();
}
这是部分视图
@model EStock.Models.WorkShop.WH_Hardware_Problem_Model
<ul style="width: 958px; margin-top: 10px;">
<li style="display:inline-block;"><h2>Hardware Problem Noted</h2></li>
<li style="float:right;"><input type="submit" value="Update All" class="btn save-exit"></li>
</ul>
<ul class="wp-hpn-headings">
<li style="width:170px; padding-left:0px;"><h3>Part Name</h3> </li>
<li><h3>Problem</h3><i>(Spoted by Lab)</i></li>
<li><h3>Solved</h3> (Yes or No)</li>
<li><h3>Reason</h3></li>
</ul>
@{int count = 1;
}
@for (int i = 0; i < Model.WH_HardwareProblem_Dtl.Count; i++)
{
<ul class="wp-ps-listing bg-white">
<li class="w_p_z">
@count<span>.</span>
<h3>
@Html.HiddenFor(m => Model.WH_HardwareProblem_Dtl[i].HardwarePartID)
@Html.LabelFor(m => Model.WH_HardwareProblem_Dtl[i].PartName, Model.WH_HardwareProblem_Dtl[i].PartName)
</h3>
</li>
<li>
@Html.LabelFor(m => Model.WH_HardwareProblem_Dtl[i].nature_of_prob, Model.WH_HardwareProblem_Dtl[i].nature_of_prob)</li>
<li>
@Html.RadioButtonFor(model=>Model.WH_HardwareProblem_Dtl[i].ProblemSolved_Status,"1")
@Html.RadioButtonFor(model => Model.WH_HardwareProblem_Dtl[i].ProblemSolved_Status, "2")
@Html.RadioButtonFor(model => Model.WH_HardwareProblem_Dtl[i].ProblemSolved_Status, "3")
</li>
<li style="width:290px;">
@Html.TextBoxFor(m => Model.WH_HardwareProblem_Dtl[i].Reason, Model.WH_HardwareProblem_Dtl[i].Reason)
@* <input type="text" class="text-field" />*@
</li>
</ul>
count++;
}
当我提交表单时,我的部分视图消失了。我能否显示强文
答案 0 :(得分:0)
从我所看到的你没有在父母(主要)视图中调用您的部分视图。
像这样:
<div>
@Html.Partial("PartialView", Model.partialModel)
</div>
如果您正在使用Razor,您还可以使用RenderPartial。
@Html.Partial("ViewName") //html.partial
@{ Html.RenderPartial("ViewName"); } //html.RenderPartial