Let's go

MVC使用方法

1.mvc打开html代码

后台处理:

  ///<summary>
        ///恢复html中的特殊字符
        ///</summary>
        ///<paramname="theString">需要恢复的文本。</param>
        ///<returns>恢复好的文本。</returns>
        public static string HtmlDiscode(string theString)
        {
            theString=theString.Replace("&gt;",">");
            theString=theString.Replace("&lt;","<");
            theString=theString.Replace("&nbsp;"," ");
            theString=theString.Replace("&quot;","\"");
            theString = theString.Replace("&#39;", "\'");
            theString=theString.Replace("<br/>","\n");
            return theString;
        }
View Code

前台页面:

@Html.Raw(ViewBag.content)
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>

 

posted @ 2019-06-05 17:12  chenze  阅读(630)  评论(0编辑  收藏  举报
有事您Q我