我有一个主窗体,它将div渲染为局部视图。我加载控件非常好。在主要表格上 我有一个控制器,当我点击按钮时,它有一个必须从局部视图表格中获取数据的功能 在局部视图上,它没有命中控制器(SaveSMRNotesFile)。
当我从局部视图中单击上传按钮时,如果我放置断点并且那不是我想要的那个,它将转到SearchUploadNotes控制器。
如何使用部分视图将数据传递给控制器?
主要表格
@using (Ajax.BeginForm("SearchUploadNotes", "UploadNotes", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "dvUploadNotes" }, new { @class = "form-horizontal", role = "form" }))
{
<div id="divControlls">
@{Html.RenderPartial("_UploadNotesControllsGridPartialV", new TTAF.Portal.Parts.Web.Models.UploadNotesFolder.UploadNotesViewModel());}
</div>
<button class="btn btn-primary " id="btnSearch" name="submit" type="submit">Search</button>
}
部分视图
@using (Html.BeginForm("SaveSMRNotesFile", "UploadNotes", FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-horizontal" , @id = "form-id", role = "form" }))
{
<button class="btn btn-primary " id="btnn" name="submit" type="sumbit" onclick="">Upload</button>
}
控制器功能
[HttpPost]
public ActionResult SaveSMRNotesFile(UploadNotesViewModel mymodel)
{
}
答案 0 :(得分:1)
解决问题的方法可能是:
主要表格
**@using (Ajax.BeginForm("SearchUploadNotes", "UploadNotes", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "dvUploadNotes" }, new { @class = "form-horizontal", role = "form" }))
{
@if(ViewBag.Control){
<div id="divControlls">
@{Html.RenderPartial("_UploadNotesControllsGridPartialV", new TTAF.Portal.Parts.Web.Models.UploadNotesFolder.UploadNotesViewModel());}
</div>
}
<input class="btn btn-primary " id="btnSearch" value="Search" type="submit" formaction="SearchUploadNotes">
}
部分视图
<!-- RENDER YOUR DIFFERENT DATA AFTER YOUR SEARCH -->
<input class="btn btn-primary " id="btnn" value="Upload" type="sumbit" formaction="SaveSMRNotesFile"/>
控制器功能
[HttpPost]
public ActionResult SaveSMRNotesFile(UploadNotesViewModel mymodel)
{
// DO YOUR STUFF COMING FROM THE DATA RECOVERED OF YOUR FORM IN A UploadNotesViewModel OBJECT
}
[HttpPost]
public ActionResult SearchUploadNotes(UploadNotesViewModel mymodel)
{
// DO YOUR STUFF COMING FROM THE DATA RECOVERED OF YOUR FORM IN A UploadNotesViewModel OBJECT. RETURNS YOUR DATA AFTER THE SEARCH AND RETURN A VIEWDATA.CONTROL BOOL FOR RENDERING YOUR PARTIAL.
}
这个想法,就我从你的帖子中得到的(对不起我的英语:)):
您将只使用搜索提交按钮呈现一个表单,如果单击该表单,您将通过ViewData.Control值呈现部分搜索数据以及用于上载的新提交按钮。
这个按钮调用,在同一个控制器中,另一个方法,为形式属性定义,称为SaveSMRNotesFile,它将完成你的工作。我想上传这些数据的新值。
希望它有所帮助。让我知道任何疑问。干杯队友。