public class TestController : Controller
{
public ActionResult Index()
{
var xmDTO = XFacade.XList();
return View(xmDTO);
}}
我的控制器看起來像,我想從我的瀏覽器訪問 名單如何做到這一點? 我不會當我使用xmDTO在一個循環如何由觀衆訪問控制器定義varibales在MVC4
public class TestController : Controller
{
public ActionResult Index()
{
var xmDTO = XFacade.XList();
return View(xmDTO);
}}
我的控制器看起來像,我想從我的瀏覽器訪問 名單如何做到這一點? 我不會當我使用xmDTO在一個循環如何由觀衆訪問控制器定義varibales在MVC4
使用ViewBag將是很好的方法
Controller類
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication4.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
ViewBag.country = new List<string>()
{
"USA",
"INDIA",
"UK"
};
return View();
}
}
}
查看
@{
ViewBag.Title = "List of string value";
}
<h2>Country List</h2>
<ul>
@foreach (string country in ViewBag .country)
{
<li>@country</li>
}
爲什麼你不能強烈地鍵入視圖?
public class TestController : Controller
{
public ActionResult Index()
{
var xmDTO = XFacade.XList();
return View(xmDTO);
}
}
在你看來
@model XList<type>
@{
ViewBag.Title = "List of string value";
}
@foreach (var item in country in Model)
{
//use properties in item
}
你應該認真鍵入 – Amila
UM使用剃刀所以它不會幫助,並在型號或viewbag&鑑於訪問它不MVC4風格 – Kalanamith
傳遞的數據將是很好的做法您的看法 –