mvc中简单从controll传递数据到前台页面(视图)
2019獨角獸企業重金招聘Python工程師標準>>>
Controller中的代碼如下:
?public class HomeController : Controller
? ? {
? ? ? ? //
? ? ? ? // GET: /Home/
?
? ? ? ? public ActionResult Index()
? ? ? ? {
? ? ? ? ? ? ViewData["test"] = "wtt";
? ? ? ? ? ? return View();
? ? ? ? }
? ? ? ?public string GetALL()
? ? ? ? {
? ? ? ? ? ? return "wtt";
? ? ? ? }
? ? }
在index中:
方法一:通過viewdata方法傳值,此時index中直接調用@ViewData["test"];“test”是自隨便取的名字
方法二:在對應index中通過form表單接收, action="/Home/GetALL"?如:
?<form action="/Home/GetALL" method="get">
? ? <button type="submit">denglu</button>
? </form>
轉載于:https://my.oschina.net/u/3522874/blog/1083515
總結
以上是生活随笔為你收集整理的mvc中简单从controll传递数据到前台页面(视图)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 企业wifi管家带来无限商机,你看到了吗
- 下一篇: C++语言——求圆柱表面积