我正在尝试将表单中的字符串发送到Controller,但单击“提交”按钮并不会向ActionResult发送任何内容。
相反,它返回错误404.我已经尝试过HttpPost和HttpGet,但两者都没有工作。
这是控制器:
public ActionResult ExistingClient()
{
ViewBag.Existing = true;
return View("LandingPage");
}
public ActionResult SearchClient(string q)
{
var client = from p in identityDb.MyUserInfo select p;
if (!string.IsNullOrEmpty(q))
{
client = client.Where(x => x.NIP_Regon.ToString() == q);
}
ViewBag.FoundClient = true;
ViewBag.Name = client.ToList().First().FirstName;
return View("LandingPage");
}
我的意见:
@{
ViewBag.Title = "LandingPage";
}
<h2>Wystaw fakturę VAT dla</h2>
<br /><br />
<div class="container-fluid">
<div class="form-group .col-md-12">
<div class="col-md-4">
@Ajax.ActionLink("Istniejący klient", "ExistingClient", "Vat", new AjaxOptions(), new { @class = "btn btn-default btn-lg" })
</div>
<div class="col-md-4">
<input type="submit" value="Nowy klient" class="btn btn-default btn-lg" />
</div>
</div>
@if(ViewBag.Existing == true)
{
<div>
@Html.Partial("_GetClientPartial")
</div>
}
</div>
部分:
@model Stacja_paliw.Models.UserInfo
@{
ViewBag.Title = "_GetClientPartial";
}
@using (Html.BeginForm("SearchClient", "Vat", "FormMethod.Get"))
{
@Html.AntiForgeryToken()
<div class="container-fluid">
<h4>Podaj NIP klienta</h4>
<div class=".col-md-12">
@Html.TextBox("q", null, new { @class = "form-control", @id = "client-search", @placeholder = "Client NIP" })
</div>
<div>
<input type="submit" value="Wyślij" class="btn btn-default btn-lg" />
</div>
@if(ViewBag.FoundClient == true)
{
@Html.Raw(ViewBag.Name);
}
</div>
}
默认路由配置:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}