comng所以在我的控制器不知道哪裏Request對象從
[HttpPost]
public ActionResult Summary(string id, Summary model)
{
int projectID;
if (Int32.TryParse(id, out projectID))
{
switch (Request["PageType"])
{
case "Results":
model = new Summary(SummaryType.SCS, GetSCSData(projectID, Request["Names"], true), projectID, SCSView.ResultsPage);
break;
case "Recipients":
model = new Summary(SummaryType.SCS, GetProjectData(projectID, Request["Names"]), projectID)
{
Names = Request["Names"],
HTMLAttachment = ParseBool(Request["HTMLAttachment"])
};
break;
default:
model = new Summary();
break;
}
}
這種方法,想知道其中Request["Names"]
是從哪裏來的。我明白這是來自我的Http請求調用的請求對象。但是它是如何構建和發送的?我知道它是與我的觀點,這看起來像這樣
using (Html.BeginForm(Summary, "Mycontroller", FormMethod.Post, new { id = "gridForm" }))
{
@(Html.Kendo().Grid(Model.scsGridList) ... kendo stuff
<input id="gridPage" name="PageType" type="hidden" value="" />
<input id="gridProjectID" name="ProjectID" type="hidden" value="@Model.ProjectID" />
<input id="gridJobs" name="Jobs" type="hidden" value="" />
<input id="gridHTMLAttach" name="HTMLAttachment" type="hidden" value="true" />
<div style="width: 100%; padding-top:5px;">
<a id="email" href="#"><span class="ui-icon ui-icon-mail-closed linkicon"></span>Email</a>
</div>
在我的JavaScript這個
$("#email").on("click", function (e) {
SendTo("Recipients");
});
function SendTo(pageType){
var values = GetSelectedValues();
if(values){
$("#gridPage").val(pageType);
$("#gridJobs").val(values);
$("#gridForm").submit();
} else {
$("#gridMessage").html("Please select a job.");
}
}
我只是混淆爲Request對象如何來填充數據如Request["HTMLAttachment"]
和Request["Names"]
。它知道映射到模型嗎?我有道理嗎?
我很好奇Id和Model從哪裏來的? –
這就是所謂的模型綁定。在這裏閱讀更多信息http://msdn.microsoft.com/en-us/magazine/hh781022.aspx,並在這裏http://msdn.microsoft.com/en-us/library/dd410405(v=vs.100).aspx – vmg