如何在mvc中使用页面加载方法调用?

时间:2012-03-27 08:59:18

标签: c# asp.net asp.net-mvc asp.net-mvc-3

我想在页面加载时调用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>
<%} %>

如何调用详细操作方法:

经典网页表单:

Pageload()
{
  if(!ispostback)
       Detail(1);
}

来自MVC。怎么做?

1 个答案:

答案 0 :(得分:3)

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