您的位置:首页 > 编程语言 > ASP

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

2012-03-23 10:06 465 查看
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 = "width: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) 编辑
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: