我如何使用具有不同表单类型(ajax 和开始表单)的局部视图表单点击控制器
How can i hit the controller using Partial View form that have different form type(ajax and begin form)
我有一个主窗体,它正在将 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)
{
}
解决您的问题的方法可能是:
主窗体
**@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.
}
据我从您那里得到的 post(抱歉我的英语不好 :))的想法是:
您将只呈现一个带有搜索提交按钮的表单,如果单击它,您将呈现您的部分,按 ViewData.Control 值,搜索到的数据加上一个新的提交按钮用于上传。
这个按钮在同一个控制器中调用,但在另一个方法中,为 formaction 属性定义,称为 SaveSMRNotesFile,它将完成您的工作。我想上传此数据的新值。
希望对您有所帮助。让我知道任何疑问。伙计,干杯。
我有一个主窗体,它正在将 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)
{
}
解决您的问题的方法可能是:
主窗体
**@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.
}
据我从您那里得到的 post(抱歉我的英语不好 :))的想法是:
您将只呈现一个带有搜索提交按钮的表单,如果单击它,您将呈现您的部分,按 ViewData.Control 值,搜索到的数据加上一个新的提交按钮用于上传。
这个按钮在同一个控制器中调用,但在另一个方法中,为 formaction 属性定义,称为 SaveSMRNotesFile,它将完成您的工作。我想上传此数据的新值。
希望对您有所帮助。让我知道任何疑问。伙计,干杯。