mvc路由執行機制:
傳送一條url 請求,如http://hostname/controllername/actionname/parameters。
其次,請求被asp. net mvc 的路由對映系統獲取, 並按照對映規則, 解析出 controllername,actionname 和parameters;
再次,到controllers 目錄下找到controllernamecontroller.cs 類, 並在這個類中找到與 actionname 同名的方法,將parameters 作為引數傳給這個方法;
最後,action 方法開始執行,完成後將返回相應檢視
四種傳值取值方式:
1.request
1. request.form:獲取以post方式提交的資料(接收form提交來的資料)
view檢視下:post方式提交資料
<% html.beginform("logonmothed ", " user ", formmethod.post); %>
或控制器下:
request.form[「」].tostring();
.aspx頁面**
$(document).ready(function ()
.js檔案**
」>
function getjsonresourcebaselist()
;param.param1=」123」;
param.param2=」456」;
param.param3=」789」;)
.controller檔案中呼叫
然後再resourcebasecontroller.cs下的getjosnresourcebaselist方法下querystring獲取引數:
request.querystring[「param1」];
request.querystring[「param2」];
request.querystring[「param3」];
2.dictionary
在控制器賦值:
dictionaryusermodel = new dictionary();
usermodel.add("userid", 「123」);
usermodel.add("username", 「456」);
viewdata["userdata"] = usermodel;
在檢視頁面取值:
<% dictionaryusermodel = viewdata["userdata"] as dictionary; %>
<%=html.textbox("txtusername", usermodel["username"].tostring())%>
接下來講兩種強型別資料的傳遞方法,viewdta 和 dynamic
說明:﹡resourcebaseeditmodelservice.geteditmodelbyid 返回型別為resourcebaseeditmodel
﹡resourcebaseeditmodel 是乙個資料實體型別如:
public class resourcebaseeditmodel
}傳遞給檢視,這裡只講強型別物件的傳遞
在控制器中賦值:
viewdata["editmodel"] = resourcebaseeditmodelservice.geteditmodelbyid(tempdeviceid.value);
在檢視頁面取值:
<% resourcebaseeditmodel localmodel = viewdata["local"] as resourcebaseeditmodel; %>
<%=html.textbox("txtdeviceid", localmodel.id%>
4. dynamic
在控制器賦值:
resourcebaseeditmodelmodel =resourcebaseeditmodelservice.geteditmodelbyid(tempdeviceid.value);
dynamic viewmodel = new expandoobject();
viewmodel.userid = model.id;
.name;
return view(viewmodel);
在檢視頁面取值:
<%@ page language="c#" inherits="system.web.mvc.viewpage" %>
<%=html.textbox("txtusername", (string)model.name)%>
<%=html.textbox("txtuserid", (string)model.id)%>
ps:**
MVC幾種傳值方式
一,model public class course public string name public class teacher public string name public listcourses public class student public string name publ...
MVC4 的簡單學習
1.html元件,提供很多有用的功能,html.textboxfor 這個是可以直接使用model中的東西的 2.2.remote特性,不好用,每次輸入,都要到後台去驗證,這個就有問題了,如果需要連庫查,肯定效能太差了,應該看一下怎麼回事 3和4都這個毛病 3.要詳細看看路由設定啊,很亂 4.如果要...
MVC4學習筆記(一) 認識MVC
mvc就是為了快速開發出乙個軟體專案,有多快了?你甚至可以在5分鐘內開發出乙個五臟俱全的軟體系統,一點也不假。mvc model view controller,模型 檢視 控制器模式 用於表示一種軟體架構模式。它把軟體系統分為三個基本部分 模型 model 檢視 view 和控制器 control...