我正在使用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>
所以我定义了一个动作方法和一个控制器名称。
但是如果我做了一个帖子那么它就不会进入我在控制器中的post action方法 - BalieNr。但它涉及到这个链接:
http://localhost:5923/sitemap.xml
如果我在post方法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(&#34; Login_IntroductionText&#34;,makeImagesResponsive:true)* @ @using(Html.BeginForm(htmlAttributes:new {@class =&#34; form&#34;})) { @ Html.AntiForgeryToken() @ Html.DisplayNameFor(model =&gt; model.Baliecode) @ Html.TextBoxFor(modelItem =&gt; modelItem.Baliecode) @ * @ Sana.SubmitButton(&#34;登录&#34;,&#34; btn btn-medium btn-login&#34;)* @ }现在它命中了post方法:)
答案 0 :(得分:0)
这有效:
@{
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(htmlAttributes: new { @class = "form" }))
{
@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>