ASP.NET MVC3开发中遇到问题以及解决方法

1.手写Model类,EF执行错误找不到表对象。

[TableAttribute("ProductEntity")]
public class ProductEntity{}

2.加载不同的Layout,在_ViewStart.cshtml中添加逻辑

@{if (Request.Url.AbsoluteUri.Contains("Manage"))
{
Layout = "~/Views/Shared/_MLayout.cshtml";
}else{
Layout = "~/Views/Shared/_LayoutLogin.cshtml";
}
}

3.图片image设置动态url
a.Detail/Creat/Edit页面:

@model TaiQiu.Models.ProductEntity
<img id="preview" src="@Html.DisplayFor(model => model.PicUrl)"/>

b.List页面:

@model IEnumerable<TaiQiu.Models.ProductEntity>   
@foreach (var item in Model)
{
<img src="@item.PicUrl" alt="@item.Title"/>
}

4.用户登录/权限

//验证用户成功后,将用户写入cookie
System.Web.Security.FormsAuthentication.SetAuthCookie(_user, false);
//后台Controller中添加Authorize,如果可以配置Users/Role
[Authorize(Users/Role = 允许账号/角色)]
public class ManageController : Controller{}

配置文件中其中Form验证

   <authentication mode="Forms">
<forms loginUrl="~/Login/" timeout="2880" />
</authentication>

5.绑定DropDownList

//Controller
ViewBag.CID = new SelectList(PE.CategroyEntity, "CID", "Categroy");
//View
@Html.DropDownList("CID","请选择")

6.View中控件样式设置

@Html.TextAreaFor(model => model.Infor, new { style = "800px;height:400px" })
或者
@Html.TextAreaFor(model => model.Infor, new { @class=样式名})
【原创】ASP.NET MVC3开发中遇到问题以及解决方法

posted @ 2012-03-22 22:06 zhxhdean 阅读(717) | 评论 (0) 编辑

【转载】MVC使用jqGrid

posted @ 2012-03-22 14:54 zhxhdean 阅读(26) | 评论 (0) 编辑

【原创】ASP.NET MVC3 从零开始一步步构建Web

posted @ 2012-03-12 22:37 zhxhdean 阅读(1676) | 评论 (10) 编辑

【原创】ASP.NET MVC3使用html编辑器(kindeditor)

posted @ 2012-03-10 21:10 zhxhdean 阅读(956) | 评论 (6) 编辑

【转载】ASP.NET MVC HtmlHelper类的辅助和扩展方法

posted @ 2012-03-09 09:53 zhxhdean 阅读(172) | 评论 (0) 编辑

原文地址:https://www.cnblogs.com/Leo_wl/p/2413185.html