@model和@Model之间的区别 [英] Difference between @model and @Model
问题描述
任何人都可以简单解释一下mvc(razor)中@model和@Model之间的区别是什么?
Hi, can any one briefly explain what is the difference between @model and @Model in mvc (razor) ?
推荐答案
1。假设你有一个班级
1. Say suppose, you have a class
public class person {
public string Name {get;set;}
}
2.您将通过控制器将此课程传递给视图,您可能会做什么,控制器将是类似的东西
2. You are going to pass this class via a controller to the view and what you might do the the controller would be something similar
public ActionResult Index()
{
var _persons= _repo.GetPersons();
return view(_persons);
}
3.你有一个声明部分的类 - 这是告诉你的观点你正在路过一个类,类型是人 - 我们使用@model语法
3. The class you have a declarative section something like - This is to tell your view that you are passing a class and the type is person - we use @model syntax
@model IEnumberable<person>
4.在您的视图正文中,该课程可用作模特
4. with in your view body, the class is available as "Model"
@foreach(var x in Model>
{
<div>@x.name</div>
}
希望这能为你带来一些亮点
问候
Bala
Hope this sheds some light for you
Regards
Bala
这篇关于@model和@Model之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!