I have a long form that's been split up into separate pages using partial views. I want to save the data entered into one partial view form when the user clicks to go to the next patial view form. Then have it so that when they come back to the previous view then the data entered will be there.
我有一个很长的表单,使用部分视图将它分割成不同的页面。当用户点击进入下一个patial视图表单时,我希望将数据保存为一个部分视图表单。这样,当他们返回到先前的视图时,输入的数据就会在那里。
So what i need is to post the data to a controller. Although what I am using for the partial view is:
我需要的是将数据发布到控制器。虽然我使用的局部视图是:
@Ajax.ActionLink("Job Information", "JobInformation", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "jobForm"})
When they click the action link it takes them to the next page (partial view)
当他们点击动作链接时它会把他们带到下一个页面(部分视图)
So how can i submit the form when they click the action link?
那么,当他们单击action链接时,我如何提交表单呢?
1 个解决方案
#1
2
how can i submit the form when they click the action link?
当他们点击动作链接时,我如何提交表格?
i need is to post the data to a controller.
我需要将数据发布到控制器。
Instead of using AJAX ActionLink use AJAX BeginForm as shown below. Lets say you have a model like below, to populate a dropdownlist.
使用AJAX BeginForm代替使用AJAX ActionLink,如下所示。假设您有一个如下所示的模型来填充下拉列表。
public class DDLModel
{
public List<SelectListItem> Items { get; set; }
public string SelectedValue { get; set; }
}
Then you have controller to display this model -
然后你有控制器显示这个模型-
@model MVC.Controllers.DDLModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@using (Ajax.BeginForm("Submit", "Ajax", new AjaxOptions { UpdateTargetId = "SellerWebSettings" }, new { id = "form1" }))
{
@Html.DropDownListFor(m => m.SelectedValue, Model.Items, "DDL")
<input type="submit" value="Click" />
}
<div id="SellerWebSettings">
</div>
In the above form, you have a AJAX BeginForm() which would make a AJAX all to another controller action which will return a PartialView. The model will also be forwarded to the partial view, as shown below -
在上面的表单中,您有一个AJAX BeginForm(),它将使AJAX全部转换为另一个控制器动作,该动作将返回一个PartialView。模型也将被转发到局部视图,如下所示
public ActionResult Submit(DDLModel model)
{
return PartialView("MyPartial",model);
}
And the partial view is as follows -
部分观点如下
@model MVC.Controllers.DDLModel
<div>
@DateTime.Now - @Model.SelectedValue
</div>
So when we select the Dropdownlist item and click on the button, we have following output -
所以当我们选择下拉列表项并点击按钮时,我们有以下输出-
#1
2
how can i submit the form when they click the action link?
当他们点击动作链接时,我如何提交表格?
i need is to post the data to a controller.
我需要将数据发布到控制器。
Instead of using AJAX ActionLink use AJAX BeginForm as shown below. Lets say you have a model like below, to populate a dropdownlist.
使用AJAX BeginForm代替使用AJAX ActionLink,如下所示。假设您有一个如下所示的模型来填充下拉列表。
public class DDLModel
{
public List<SelectListItem> Items { get; set; }
public string SelectedValue { get; set; }
}
Then you have controller to display this model -
然后你有控制器显示这个模型-
@model MVC.Controllers.DDLModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@using (Ajax.BeginForm("Submit", "Ajax", new AjaxOptions { UpdateTargetId = "SellerWebSettings" }, new { id = "form1" }))
{
@Html.DropDownListFor(m => m.SelectedValue, Model.Items, "DDL")
<input type="submit" value="Click" />
}
<div id="SellerWebSettings">
</div>
In the above form, you have a AJAX BeginForm() which would make a AJAX all to another controller action which will return a PartialView. The model will also be forwarded to the partial view, as shown below -
在上面的表单中,您有一个AJAX BeginForm(),它将使AJAX全部转换为另一个控制器动作,该动作将返回一个PartialView。模型也将被转发到局部视图,如下所示
public ActionResult Submit(DDLModel model)
{
return PartialView("MyPartial",model);
}
And the partial view is as follows -
部分观点如下
@model MVC.Controllers.DDLModel
<div>
@DateTime.Now - @Model.SelectedValue
</div>
So when we select the Dropdownlist item and click on the button, we have following output -
所以当我们选择下拉列表项并点击按钮时,我们有以下输出-