您的位置:首页 > 其它

《MVC 系列》- 入门案例

2017-12-28 00:00 323 查看

项目结构



新建项目



选择模板



控制器类

public class HelloController : Controller
{
// GET: /Hello/Index
public ActionResult Index()
{
//自动匹配与Action名相同的视图
return View();
}

// GET: /Hello/Index2
public ActionResult Index2()
{
//指定具体的视图名,逻辑地址
return View("Index");
}

// GET: /Hello/Index3
public ActionResult Index3()
{
//指定具体的视图名,绝对路径
return View("/Views/Hello/Index.cshtml");
}
}


视图文件

@{
ViewBag.Title = "Index";
}

<h2>Welcome to MVC</h2>


测试

在浏览器输入http://localhost:2290/Hello/Index
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MVC