我想在页面加载时调用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。怎么做?
答案 0 :(得分:3)
if (true) // some condition
{
return RedirectToAction("Detail", "Customer", new { id = 1 });
}