MVC4制作网站教程第三章 修改用户组操作3.3
程序员文章站
2023-12-04 22:32:10
一、用户
二、用户组
2.1浏览用户组
2.2添加用户组
2.3修改用户组
首先打开【usergrou...
一、用户
二、用户组
2.1浏览用户组
2.2添加用户组
2.3修改用户组
首先打开【usergroupcontroller】,修改[edit(int id)] action
/// <summary> /// 修改用户组 /// </summary> /// <param name="id">用户组id</param> /// <returns></returns> [adminauthorize] public actionresult edit(int id) { usergrouprsy = new usergrouprepository(); var _usergroup = usergrouprsy.find(id); return view(_usergroup); }
右键添加强类型视图,并修改视图代码(与添加用户组类似)
@model ninesky.models.usergroup @{ viewbag.title = "修改用户组"; layout = "~/views/layout/_manage.cshtml"; } <div class="left"> <div class="top"></div> 左侧列表 </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("eidt","usergroup")) { @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.displaytextfor(model => model.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") }
修改处理action[eidt(usergroup usergroup)]
[httppost] [adminauthorize] public actionresult eidt(usergroup usergroup) { usergrouprsy = new usergrouprepository(); var _usergroup = usergrouprsy.find(usergroup.usergroupid); if (_usergroup == null) { error _e = new error { title = "用户组不存在", details = "修改用户时发生错误,修改的用户组不存在。", cause = "该用户组已被其他管理员删除", solution = server.urlencode("<li>返回<a href='" + url.action("list", "usergroup") + "'>用户组列表</a></li>") }; return redirecttoaction("manageerror", "prompt", _e); } _usergroup.name = usergroup.name; _usergroup.description = usergroup.description; if (usergrouprsy.update(_usergroup)) { notice _n = new notice { title = "修改成功", details = "成功修改了用户组信息", dwelltime = 3, navigationname = "用户组列表", navigationurl = url.action("list", "usergroup") }; return redirecttoaction("managenotice", "prompt", _n); } else { error _e = new error { title = "更新数据失败", details = "修改用户组信息时修改的信息未能保存到数据库。", cause = server.urlencode("<li>您并未更改用户组信息。</li><li>数据库未知错误。</li>"), solution = server.urlencode("<li>返回<a href='" + url.action("list", "usergroup") + "'>用户组列表</a></li><li>重新<a href='" + url.action("edit", "usergroup", new { id = usergroup.usergroupid }) + "'>修改用户组</a></li>") }; return redirecttoaction("manageerror", "prompt", _e); } }
浏览器中打开看一下
点保存
代码打包地址:http://xiazai.jb51.net/201608/yuanma/ninesky(jb51.net).rar
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇: Python简单计算文件夹大小的方法