最近在公司做一个股票频道的项目,web层的开发需要用mvc开发,以前没用过,这段时间在慢慢的琢磨.
这里是对Html.ActionLink Url.Action的用法的一些体会
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Shumi.Stocks.CompanyInfo>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>公司概况</title>
</head>
<body>
<% Html.BeginForm("CompanyInfo", "Company", FormMethod.Get, new { id = "form1" }); %>
<div>
<a href="<%=Url.Action("CompanyInfo", "Company", new { stockId = "11111" })%>" > 查询</a>
<div>
<input name="stockId" type="text" id="stockId" class="txt" />
<input type="submit" name="btnQuery" value="查询" id="btnQuery" />
</div>
<%= Html.ActionLink("主营业务", "CompanyInfo", "Company", new { stockId = "22222" }, null)%>
<% Html.EndForm(); %>
</body>
</html>
controller中的action特性默认是HttpGet
要注意的是action中的方法参数必须和Url.Action,Html.ActionLink传入的id一致
/// <summary>
/// 公司概况
/// </summary>
/// <returns></returns>
public ActionResult CompanyInfo(string stockId)
{
string id = stockId;
// stockId = stockId ?? 111;
// CompanyInfo cinfo = CompanyInfoClient.Instance.GetCompanyInfo("8BBB337A-AB56-409F-A454-3F735AEA14C2");
// ViewData["cinfo"] = cinfo;T
return View();
}