新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Request.Form與Request.QueryString使用
controler控制器代碼 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace asp.net_mvc_Demo2.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { #region Request.QueryString ////第一步,設置與前臺交互 ////Request.QueryString,用于method的“Get”獲取的是前臺輸入的查詢字符串, ////http://localhost:27123/Home/Index?key=1245 //string str = Request.QueryString["key"];//返回的是查詢字符串中“?”后的數(shù)值 ////第二步:業(yè)務邏輯處理 //str = str ?? string.Empty;//新語法,如果str為空則返回string.Empty否則則為str ////第三步:將數(shù)據(jù)返回前臺 //ViewData["demo"] = str; #endregion #region Request.Form使用 //Request.Form中使用的是Method的方式是“post”,得必須提交給服務器,例如使用submit表單 string str1 = Request.Form["txt"]; str1 = str1 ?? "獲取值為空"; TempData["demo1"] = str1; #endregion return View(); } } } View視圖代碼 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> Index
網(wǎng)頁題目:Request.Form與Request.QueryString使用
標題路徑:http://fisionsoft.com.cn/article/gsgehh.html