我正在尝试将我的模型从视图传递到控制器的强类型。我的观点是强类型的。当在控制器中调用“保存”操作方法时,我以某种方式在属性值中得到“空”。我正在使用Asp.Net MVC 3
.
这就是我的视图的样子:
@model MvcApplication2.Models.Event
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>AddNew</title>
</head>
<body>
@using(Html.BeginForm("Save","Event",FormMethod.Post, Model))
{
<div>
<p>@Html.LabelFor(m=>m.EventName) @Html.TextBoxFor(m=>m.EventName)</p>
<p>@Html.LabelFor(m=>m.Venue) @Html.TextBoxFor(m=>m.Venue)</p>
<p>@Html.LabelFor(m=>m.StartTime) @Html.TextBoxFor(m=>m.StartTime)</p>
<p>@Html.LabelFor(m=>m.EndTime) @Html.TextBoxFor(m=>m.EndTime)</p>
@Html.ActionLink("Save Event", "Save")
</div>
}
</body>
</html>
这就是我的EventController
样子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication2.Models;
namespace MvcApplication2.Controllers
{
public class EventController : Controller
{
public string Save(Event eventModel)
{
//Here eventModel.EventName and rest of the properties are null.
return "Saved";
}
}
}
这是模型的样子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcApplication2.Models
{
public class Event
{
public string EventName { get; set; }
public string Venue { get; set; }
public string StartTime { get; set; }
public string EndTime { get; set; }
}
}