ASP.NET MVC 4使用EF显示来自2个模型的数据(ASP.NET MVC 4 Display data From 2 Model using EF)
我开始学习ASP.NET MVC 4并在1文件中停留显示数据来自2模型这是我的模型
public class mst_item { [Key] [DisplayName("Item Code")] [Required] public string item_code{get;set;} [DisplayName("Item Name")] [Required] public string item_name{get;set;} [DisplayName("Unit")] [Required] public mst_item_unit unit_id{ get; set; } } public class mst_item_unit { [Key] public int unit_id { get; set; } [DisplayName("Unit")] public string unit_name { get; set; } }
然后我的控制器:
public ActionResult Item() { var list_item = db.mst_item.Include("mst_item_unit").ToList(); return View(list_item); }
那么如何使用
INNER JOIN
或Include
在View中显示基于mst_item.unit_id
? 就像是 :@foreach (var item in Model) { @Html.DisplayFor(modelItem => item.item_name) @Html.DisplayFor(modelItem => item.unit_name) }
我被
mst_item
,但我成功地显示mst_item
数据而没有加入mst_item_unit
(只是显示基于mst_item.unit_id
的ID)之前。I'm start learning ASP.NET MVC 4 and stuck displaying Data From 2 model in 1 File Here's my Model
public class mst_item { [Key] [DisplayName("Item Code")] [Required] public string item_code{get;set;} [DisplayName("Item Name")] [Required] public string item_name{get;set;} [DisplayName("Unit")] [Required] public mst_item_unit unit_id{ get; set; } } public class mst_item_unit { [Key] public int unit_id { get; set; } [DisplayName("Unit")] public string unit_name { get; set; } }
Then My Controller :
public ActionResult Item() { var list_item = db.mst_item.Include("mst_item_unit").ToList(); return View(list_item); }
Then How to display the unit_name based on the
mst_item.unit_id
in View usingINNER JOIN
orInclude
? something like :@foreach (var item in Model) { @Html.DisplayFor(modelItem => item.item_name) @Html.DisplayFor(modelItem => item.unit_name) }
I get stuck here, But I success while displaying the
mst_item
data without joiningmst_item_unit
(just display the ID based onmst_item.unit_id
) before.
原文:https://stackoverflow.com/questions/28324932
最满意答案
在struct Mid中,使用返回类型声明函数是Int,但在该函数中,返回元组(x,y)。 一定是:
struct Mid{ var origin:Point, sise:Sise; func calc() -> (Int,Int) { var x = origin.x + (sise.width/2) var y = origin.y + (sise.height/2) return (x,y) } }
In the struct Mid, you declare your function with return type is Int but in that function, you return a tuple (x,y). It must be:
struct Mid{ var origin:Point, sise:Sise; func calc() -> (Int,Int) { var x = origin.x + (sise.width/2) var y = origin.y + (sise.height/2) return (x,y) } }
相关问答
更多-
你的函数头表示你正在返回一个闭包,它接受一个Int并返回一个String ,这就是你的函数应该返回的。 下面是一个使用所有输入构造String的示例: func doSomeThing(productName: String, productPrice: Double) -> (Int) -> String { return { n in "\(n) \(productName)s cost \(productPrice * Double(n))" } } let iPhone = doSomeT ...
-
是否可以使用int -> (int -> int)类型的表达式? 因为->是右关联的,所以类型为int -> (int -> int) = int -> int -> int ,尽管暗示了括号。 所以你正在寻找的函数是一个简单的curried函数,它有两个参数,例如 let f x y = x + y Is it possible to have an expression with int -> (int -> int) type? Because -> is right-associative, th ...
-
根据您使用result您可以使用委托类型Func
动态创建它Func 并将其键入为LambdaExpression : ParameterExpression entityParameter = Expression.Parameter(typeof(Entity), "e"); Expression propertyAccess = Expression.Property(entityParameter, property); var funcType ... -
在struct Mid中,使用返回类型声明函数是Int,但在该函数中,返回元组(x,y)。 一定是: struct Mid{ var origin:Point, sise:Sise; func calc() -> (Int,Int) { var x = origin.x + (sise.width/2) var y = origin.y + (sise.height/2) return (x,y) } } In the struct ...
-
你不需要一个值,只需要枚举类型。 你可以使用这样的东西 通用 public static List
GetEnumList () where TEnum : struct, IConvertible, IFormattable { return ((TEnum[])Enum.GetValues(typeof(TEnum))).Select(v => new SelectListItem { Text = v.ToString ... -
gdb不知道方法(或函数)的返回类型: (gdb) p [@"-1" floatValue] Unable to call function "objc_msgSend" at 0x155d08c: no return type information available. To call this function anyway, you can cast the return type explicitly (e.g. 'print (float) fabs (3.0)') 将表达式转换为int ,g ...
-
如果你检查Date类..你可以发现public typealias NSTimeInterval = Double意味着返回类型是NSTimeInterval的双精度.. 和方法是 public convenience init(timeInterval secsToBeAdded: NSTimeInterval, sinceDate date: NSDate) // timeInterval -> return NSTimeInterval // date -> return NS ...
-
该表达式的类型为int,但在此处使用type unit(This expression has type int but is here used with type unit)[2022-06-16]
在F#中,函数的返回值是函数中最后一个表达式。 所以,让我们关注以下内容: if ex < 1 then if ex = 0 then res (* <--- this is not an early return *) ex <- -ex (* <--- F# evaluates this code after the *) n <- 1 / n (* if statement *) 此外,如果语句具 ... -
“奇怪的”编译器错误 Cannot convert return expression of type '[Int]' to return type '[Int]' 可以解释如下: 类定义中的
和方法定义中的 都引入了一个名为Int的新泛型类型占位符(因此外部 隐藏了具有相同名称的全局类型,并且内部 隐藏外面的)。 你的类定义相当于 class IntDataSource: DataSource { let data:[A] = [] func get ... -
model=>model.LAST_UPDATE_BY从Expression<...>类型生成一个参数。 (有关示例,请参阅Html.EditorFor() 。 你的CustomHelpers方法想要一个int类型的参数,所以你必须调用它: @CustomHelpers.UserNameForID(Model.LAST_UPDATE_BY) model=>model.LAST_UPDATE_BY generates an argument from type Expression<...>. (For a ...