MVC4制作網(wǎng)站教程第三章 添加用戶組操作3.2
一、用戶
二、用戶組
2.1瀏覽用戶組
2.2添加用戶組
修改[Add]Action
/// <summary>
/// 添加用戶組
/// </summary>
/// <returns></returns>
[AdminAuthorize]
public ActionResult Add()
{
ViewData.Add("Type", TypeSelectList);
return View();
}
添加強(qiáng)類型視圖

完成后代碼如下:
@model Ninesky.Models.UserGroup@{
ViewBag.Title = "添加用戶組";
Layout = "~/Views/Layout/_Manage.cshtml";
}
<div class="left">
<div class="top"></div>
左側(cè)列表
</div>
<div class="split"></div>
<div class="workspace">
<div class="inside">
<div class="notebar">
<img alt="" src="~/Skins/Default/Manage/Images/UserGroup.gif" />添加用戶組
</div>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>用戶組資料</legend>
@Html.HiddenFor(model => model.UserGroupId)
<ul>
<li>
<div class="editor-label">
@Html.LabelFor(model => model.Type)
</div>
<div class="editor-field">
@Html.DropDownList("Type")
</div>
</li>
<li>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
</li>
<li>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
</li>
<li>
<div class="editor-label">
</div>
<div class="editor-field">
<input type="submit" value="保存" />
</div>
</li>
</ul>
</fieldset>
}
</div>
</div>
<div class="clear"></div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
修改用戶組添加處理動(dòng)作[Add(UserGroup userGroup)]Action,完成后的代碼
[HttpPost]
[AdminAuthorize]
public ActionResult Add(UserGroup userGroup)
{
userGroupRsy = new UserGroupRepository();
if (userGroupRsy.Add(userGroup))
{
Notice _n = new Notice { Title = "添加用戶組成功", Details = "您已經(jīng)成功添加["+userGroup.Name+"]用戶組!", DwellTime = 5, NavigationName = "用戶組列表", NavigationUrl = Url.Action("List", "UserGroup") };
return RedirectToAction("ManageNotice", "Prompt", _n);
}
else
{
Error _e = new Error { Title = "添加用戶組失敗", Details = "在添加用戶組時(shí),未能保存到數(shù)據(jù)庫", Cause = "系統(tǒng)錯(cuò)誤", Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("Add", "UserGroup") + "'>添加用戶</a>頁面,輸入正確的信息后重新操作</li><li>聯(lián)系網(wǎng)站管理員</li>") };
return RedirectToAction("ManageError", "Prompt", _e);
}
}
瀏覽器中查看一下

輸入資料測(cè)試一下,可以添加資料。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- ASP.NET MVC5網(wǎng)站開發(fā)管理列表、回復(fù)及刪除(十三)
- ASP.NET MVC5網(wǎng)站開發(fā)我的咨詢列表及添加咨詢(十二)
- ASP.NET MVC5網(wǎng)站開發(fā)修改及刪除文章(十)
- ASP.NET?MVC5網(wǎng)站開發(fā)顯示文章列表(九)
- ASP.NET MVC5網(wǎng)站開發(fā)添加文章(八)
- ASP.NET MVC5網(wǎng)站開發(fā)文章管理架構(gòu)(七)
- ASP.NET MVC5網(wǎng)站開發(fā)用戶修改資料和密碼(六)
- ASP.NET?MVC5網(wǎng)站開發(fā)用戶登錄、注銷(五)
- ASP.NET?MVC5?網(wǎng)站開發(fā)框架模型、數(shù)據(jù)存儲(chǔ)、業(yè)務(wù)邏輯(三)
- ASP.NET MVC5網(wǎng)站開發(fā)項(xiàng)目框架(二)
相關(guān)文章
asp.net(vb.net)獲取真實(shí)IP的函數(shù)
asp.net(vb.net)獲取真實(shí)IP的函數(shù),需要的朋友可以參考下。2010-11-11
使用asp.net改變網(wǎng)頁上圖片顏色比如灰色變彩色
要能在網(wǎng)站上改變圖片的顏色,比如灰色的變成彩色,彩色的變成灰色多好啊,下面是通過asp.net實(shí)現(xiàn)的,有需求的朋友可以參考下2014-08-08
ASP.NET實(shí)現(xiàn)推送文件到瀏覽器的方法
這篇文章主要介紹了ASP.NET實(shí)現(xiàn)推送文件到瀏覽器的方法,可實(shí)現(xiàn)將文件推送到瀏覽器供用戶瀏覽或下載的功能,需要的朋友可以參考下2015-06-06
Asp.net Socket客戶端(遠(yuǎn)程發(fā)送和接收數(shù)據(jù))
通過Socket遠(yuǎn)程發(fā)送與接收數(shù)據(jù)的代碼類2008-11-11

