1月14号 MVC使用方法

85 阅读1分钟

1.mvc打开html代码

后台处理:

 View Code

前台页面:

 View Code

 2、返回多个对象

复制代码

public ActionResult LookView(Guid id)
{
    EntityA _entityA = db.Set<EntityA>().Where(c => c.id == id).SingleOrDefault();  //表A
    EntityB _entityB = db.Set<EntityB>().Where(c => c.id == id).SingleOrDefault();  //表B
    if (_entityA == null)
    {
        _entityA = new EntityA();
    }
    if (_entityB == null)
    {
        _entityB = new EntityB();
    }
    return View(Tuple.Create(EntityA, EntityB));
}

复制代码

前台页面

复制代码

@{
 
    Layout = null;
}
@model Tuple<Model.EntityA, Model.EntityB>
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>LookView</title>
<head>
<body>
    @*取 Model.EntityA字段值*@
     <input type="text" name="字段1" class="hbes-input" value="@Html.DisplayFor(model => model.Item1.字段1)" />
</body>
    @*取 Model.EntityB 字段值*@
    <input type="text" name="字段2" class="hbes-input" value="@Html.DisplayFor(model => model.Item2.字段2)" />
</body>
</html>