i灣調用,而頁面加載MVC控制器的方法:如何使用mvc中的頁面加載方法調用?
public ActionResult Detail(int id)
{
Customer customer = CustomerManager.GetCustomer(id);
return View(customer);
}
我的視圖代碼:
<h2>Detail</h2>
<%=Html.ValidationSummary("Please correct the erros and try again.") %>
<% using (Html.BeginForm("Detail", "Customer", new { id = 1 }))
{%>
<fieldset>
<legend>Fields</legend>
<p>
<%=Html.LabelFor(q => q.id)%>
<%=Html.Encode(Model.id)%>
</p>
<p>
<%=Html.LabelFor(q => q.Name)%>
<%=Html.DisplayFor(q => q.Name)%>
</p>
<p>
<%=Html.LabelFor(q => q.SurName)%>
<%:Html.Encode(Model.SurName)%>
</p>
<p>
<%=Html.ActionLink("Edit", "Edit", new { id = Model.id })%>
</p>
</fieldset>
<%} %>
如何呼叫詳細操作方法:
經典Web窗體:
Pageload()
{
if(!ispostback)
Detail(1);
}
TO
MVC from。怎麼做?
您可以將您的引薦網址寫入會話。每個請求,請檢查引薦網址字符串是否等於request.url,然後調用Detail(id)。由於MVC是無狀態的,我認爲沒有回傳屬性。 – 2012-03-27 09:05:10