【发布时间】:2017-08-16 07:01:00
【问题描述】:
我正在使用 asp.net mvc4。
我有一个控制器:
public class ExtendedProfileController : ProfileController
{
protected override void RegisterSystemRoutes(SanaRouteCollection routes)
{
routes.MapSystemPageRoute("Profile", "BalieNr", "BalieNr", "Profile/BalieNr");
base.RegisterSystemRoutes(routes);
}
[HttpGet]
public ActionResult Hallo()
{
return View();
}
[HttpGet]
public ActionResult BalieNr()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult BalieNr(IEntityListLoadOptions options, string accountID, ExtendedSalesAgentInfoModel model /*string accountId, ShopAccountType accountType,Customer.ICustomerListLoadOptions hallo*/)
{
var salesAgent = CommerceFramework.ShopAccounts.GetShopAccounts(options);
foreach (var item in salesAgent)
{
if (item.ShopAccountType == ShopAccountType.SalesAgent)
{
if (item.ReferenceId.Contains("DB"))
{
Console.WriteLine("true");
}
var customer = CommerceFrameworkBase.SalesPersons.GetSalesPerson(accountID);
Console.WriteLine(accountID);
}
else
Console.WriteLine("false");
}
Console.WriteLine(salesAgent);
return View();
}
}
方法BalieNr是主要方法。
所以我也有一个看法,像这样:
@{
Layout = LayoutPaths.General;
}
@model Sana.Commerce.Customization.Account.ExtendedSalesAgentInfoModel
<div class="semicolumn">
@*<div class="text">@Sana.RichText("Login_IntroductionText", makeImagesResponsive: true)</div>*@
<div class="form-holder">
@using (Html.BeginForm("BalieNr", "ExtendedProfileController", FormMethod.Post))
{
@Html.AntiForgeryToken()
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Baliecode)
</th>
<th></th>
</tr>
<tr>
<td>
@Html.TextBoxFor(modelItem => modelItem.Baliecode)
</td>
</tr>
</table>
<div class="form-row">
@*@Sana.SubmitButton("Login", "btn btn-medium btn-login")*@
<input type="submit" value="Login" />
</div>
}
</div>
<div>
</div>
</div>
所以我定义了一个动作方法和一个控制器名称。
但是,如果我发布帖子,那么它不会转到控制器中的帖子操作方法 - BalieNr。但它转到此链接:
http://localhost:5923/sitemap.xml
如果我在发布方法 BalieNr 上设置一个断点。它没有达到那个方法。
那么如何解决它,使其命中 post 方法 BalieNr?
谢谢
如果我这样做:
@using (Html.BeginForm("BalieNr", "ExtendedProfile", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Baliecode)
</th>
<th></th>
</tr>
<tr>
<td>
@Html.TextBoxFor(modelItem => modelItem.Baliecode)
</td>
</tr>
</table>
<div class="form-row">
@*@Sana.SubmitButton("Login", "btn btn-medium btn-login")*@
<input type="submit" value="Login" />
</div>
}
仍然没有找到正确的方法。
我是这样做的:
@{
Layout = LayoutPaths.General;
}
@model Sana.Commerce.Customization.Account.ExtendedSalesAgentInfoModel
@*@Sana.RichText("Login_IntroductionText", makeImagesResponsive: true)*@ @using (Html.BeginForm(htmlAttributes: new { @class= "form" })) { @Html.AntiForgeryToken() @Html.DisplayNameFor(model => model.Baliecode) @Html.TextBoxFor(modelItem => modelItem.Baliecode) @*@Sana.SubmitButton("登录", "btn btn-medium btn-login")*@ }现在它命中了 post 方法:)
【问题讨论】:
-
尝试将 'using (Html.BeginForm("BalieNr", "ExtendedProfileController", FormMethod.Post))' 更改为 ' using (Html.BeginForm("BalieNr", "ExtendedProfile", FormMethod.发布))'
-
感谢您的回复。我编辑帖子
-
嗯,您确定您正在处理的视图实际上与您的 ActionResult 相关联吗?尝试右键单击您的 ActionResult 并按“转到查看”并检查它是否已链接。如果没有,请右键单击 ActionResult 并按“添加视图..”
-
在它自带的 GET 方法中。巴列号问题是我只能扩展控制器。但是 BalieNr 的独立视图可以正确加载。问题出在 post 方法上。
-
可能是路由问题?你能显示你的 RouteConfig 吗?
标签: asp.net asp.net-mvc post