在开始这个主题之前我先简要介绍一下如何在ActionMethod中通过Form使用Post的方式进行传递参数
原生类型参数传递
public ActionResult SimplePost(string number){ ViewData[Title] = SimplePost Page; ViewData[Message] = Increase :; #region Increase SimplePostModel model = new SimplePostModel(); int result; if (!stringIsNullOrEmpty(number)) { if (intTryParse(number out result)) { modelSimplePostResult = result; ViewData[number] = modelIncrease(); } else { ViewData[number] = number; } } else { ViewData[number] = modelSimplePostResult; } #endregion return View();}
先看一个简单的示例
<%@ Page Language=C# AutoEventWireup=true MasterPageFile=~/Views/Shared/SiteMaster CodeBehind=SimplePostaspxcs Inherits=MvcAppWarningPostWithHtmlHelperViewsHomeSimplePost %><%@ Import Namespace=MvcAppWarningPostWithHtmlHelperModels %><asp:Content ID=indexContent ContentPlaceHolderID=MainContent runat=server> <h> <%= HtmlEncode(ViewData[Message]) %>