我的CreateController.cs
:
using System.Web.Mvc;
using ClientDAL;
using Services;
using ShardingMvcDemo.Raven;
using ShardingMvcDemo.ViewModels;
namespace ShardingMvcDemo.Controllers
{
public class CreateController : Controller
{
//
// GET: /Create/
public ActionResult Index()
{
return View();
}
//
// POST: /Create/
[HttpPost]
public ActionResult Create(ClientViewModel client)
{
try
{
var ravenDbConnection = new RavenDbConnection(new RavenDbConnectionManager());
var service = new ClientService(ravenDbConnection);
service.AddClient(client.FirstName, client.LastName, client.Country);
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
我的Create/Index.cshtml
看法:
@model ShardingMvcDemo.ViewModels.ClientViewModel
@{
ViewBag.Title = "Create a client";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Client</legend>
<div class="editor-label">
@Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FirstName)
@Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LastName)
@Html.ValidationMessageFor(model => model.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Country)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Country)
@Html.ValidationMessageFor(model => model.Country)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
当我单击表单中的提交按钮时,[HttpPost]
甚至没有触发该方法(在调试模式下检查)。我究竟做错了什么?