问题描述
你好。 我对MVC很新 我创建了一个局部视图如下: 控制器
Hello there I am very new to MVC I have created a partial view as bellow the controller
public class Pv_AddressController : BaseController
{
//
// GET: /Pv_Address/
public ActionResult Index()
{
AddressModel model = new AddressModel();
return View(model);
}
//
// GET: /Pv_Address/Details/5
public ActionResult GetAddress(string home, string postcode)
{
List< AddressModel> model = AddressUtility.FindAddressByPostcode(home, postcode,false);
return View(model);
}
查看以下索引
view for Index as bellow
@model Account_Portal.Models.AddressModel
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>AddressModel</h4>
<hr />
<p>
@Html.Label("House Number or Name")
@Html.EditorFor(model => model.AddressLine1)
</p>
<p>
@Html.LabelFor(model => model.Postcode)
@Html.EditorFor(model => model.Postcode)
</p>
</div>
}
<div>
@Html.ActionLink("Continue", "GetAddress", new { home = Model.AddressLine1, postcode =Model.Postcode })
@Html.ActionLink("Don't Know the Postcode", "ManuallyEnter", new { type = "ManuallyAdd" })|
@Html.ActionLink("BFPO Customer", "ManuallyEnter", new { type = "BFPO" })
</div>
现在我想要包括局部视图AddressChangeController 我得到的控制器是
now I wanted is to include the partial view the AddressChangeController the controller i have got is
public class AddressChangeController : Controller
{
//
// GET: /ChangeBillingAddress/
public ActionResult Index()
{
ChangeAddressModel model = new ChangeAddressModel();
return View(model;
}
和视图是
and the view is
@model AccountPortal.Models.ChangeBillingAddressModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
//want to include the pv_addressController
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
</body>
</html>
我如何在主视图中包含pv_addressController 感谢所有帮助
how do i include the pv_addressController in my main view appreciate all your help
推荐答案
首先,当你打电话给任何人时部分视图的操作然后你返回作为PartialView(); 从你的.aspx或.cshtml你必须在 $ b之后调用Action $ b First of all, when you call any action for partial view then you have return the as PartialView(); From your .aspx or .cshtml you have to call the Action after
@Html.AntiForgeryToken();
@Html.Action("Index","AddressChangeController");