2012-03-27 62 views
0

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。怎麼做?

+0

您可以將您的引薦網址寫入會話。每個請求,請檢查引薦網址字符串是否等於request.url,然後調用Detail(id)。由於MVC是無狀態的,我認爲沒有回傳屬性。 – 2012-03-27 09:05:10

回答

3
if (true) // some condition 
{ 
    return RedirectToAction("Detail", "Customer", new { id = 1 }); 
} 
+0

:d是真的.. – Bas 2012-03-27 09:04:35

+0

這也將(作爲副作用)渲染細節方法相關的觀點,而不是渲染與原始請求 – Bond 2012-03-27 11:32:43

+0

是的,你說得對相關聯的視圖。這是爲了查看<%= Html.Action(「Detail」,「Customer」,new {id = 1})%> – Anton 2012-03-27 11:38:47

相關問題