In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
MVC4 production website how to update the column, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
I. users
II. User groups
III. Columns
3.1 add columns
3.2 browse the column
3.3 Update column
Click the column name in the tree list and jump to the details page ~ / Category/ManageDetails/id. Click modify on the detailed page to complete the column data modification.
Open [CategoryController] and add [ManageDetails (int id)] action first.
/ column details / public ActionResult ManageDetails (int id) {categoryRsy = new CategoryRepository (); var _ node = categoryRsy.Find (id) If (_ node = = null) {Error _ e = new Error {Title = "column does not exist", Details = "column does not exist", Cause = Server.UrlEncode ("column has been deleted"), Solution = Server.UrlEncode ("return column management")}; return RedirectToAction ("ManageError", "Prompt", _ e);} ModuleRepository _ moduleRsy = new ModuleRepository () Var _ modules = _ moduleRsy.List (true); List _ slimodule = new List (_ modules.Count ()); foreach (Module _ module in _ modules) {if (_ node.Model = = _ module.Model) _ slimodule.Add (new SelectListItem {Text = _ module.Name, Value = _ module.Model, Selected = true}); else _ slimodule.Add (new SelectListItem {Text = _ module.Name, Value = _ module.Model}) } ViewData.Add ("Model", _ slimodule); var _ type = TypeSelectList; _ type.SingleOrDefault (t = > t.Value = = _ node.Type.ToString ()). Selected = true; ViewData.Add ("Type", _ type); return View (_ node);}
The code first looks at whether the column exists, and there is no jump to the error page, followed by the ViewData that adds "Model" and "Type".
Right-click to enhance the type view ManageDetails.cshtml, which is basically similar to ManageAdd.cshtml.
@ model Ninesky.Models.Category@ {ViewBag.Title = "column information"; Layout = "~ / Views/Layout/_Manage.cshtml";}
Column information @ using (Html.BeginForm ("ManageUpdate") "Category") {@ Html.ValidationSummary (true) details @ Html.HiddenFor (model = > model.CategoryId) @ Html.LabelFor (model = > model.CategoryId) @ Html.DisplayTextFor (model = > model.CategoryId) Html.LabelFor (model = > model.Name) @ Html.EditorFor (model = > model.Name) @ Html.ValidationMessageFor (model = > model.Name) @ Html.LabelFor (model = > model.ParentId) @ Html.TextBoxFor (model = > model.ParentId New {@ class = "easyui-combotree", data_options = "url:'" + Url.Action ("JsonTreeParent" "Category") + "'"}) @ Html.ValidationMessageFor (model = > model.ParentId) @ Html.LabelFor (model = > model.Type) @ Html.DropDownList ("Type") @ Html.ValidationMessageFor (model = > model.Type) Html.LabelFor (model = > model.Model) @ Html.DropDownList ("Model") @ Html.ValidationMessageFor (model = > model.Model) @ Html.LabelFor (model = > model. CategoryView) @ Html.EditorFor (model = > model.CategoryView) @ Html.ValidationMessageFor (model = > model.CategoryView) @ Html.LabelFor (model = > model.ContentView) @ Html.EditorFor (model = > model.ContentView) Html.ValidationMessageFor (model = > model.ContentView) @ Html.LabelFor (model = > model.Navigation) @ Html.EditorFor (model = > model.Navigation) @ Html.ValidationMessageFor (model = > model.Navigation) Html.LabelFor (model = > model.Order) @ Html.EditorFor (model = > model.Order) @ Html.ValidationMessageFor (model = > model.Order) } @ Html.Action ("ManagePartialTree") "Category") Details () $("# Type") .change (function () {Details ();}); function Details () {var v = $("# Type") .val (); if (v = "0") {$("# li_model") .show (); $("# li_categoryview") .show (); $("# li_contentview") .show (); $("# li_nav"). Hide () $("# Navigation"). Val (");} else if (v = =" 1 ") {$(" # li_model ") .hide (); $(" # li_categoryview ") .show (); $(" # li_contentview ") .hide (); $(" # ContentView ") .val ("); $(" # li_nav ") .hide () $("# Navigation"). Val (");} else if (v = =" 2 ") {$(" # li_model ") .hide (); $(" # li_categoryview ") .hide (); $(" # CategoryView ") .val ("); $("# li_contentview") .hide (); $("# ContentView") .val ("") $("# li_nav"). Show ();} @ section Scripts {@ Styles.Render ("~ / EasyUi/icon") @ Scripts.Render ("~ / bundles/EasyUi") @ Scripts.Render ("~ / bundles/jqueryval")}
Note that @ using (Html.BeginForm ("ManageUpdate", "Category")); indicates that the data is submitted to ManageUpdate after clicking the modify button. Let's start doing this action.
Add [ManageUpdate] action in httppost mode to [CategoryController]
/ / modify column information / public ActionResult ManageUpdate (Category category) {switch (category.Type) {case 0: category.Navigation = ""; break; case 1: category.Model = ""; category.ContentView = ""; category.Navigation = "" Break; case 2: category.Model = "; category.CategoryView ="; category.ContentView ="; break;} categoryRsy = new CategoryRepository (); if (categoryRsy.Update (category)) {Notice _ n = new Notice {Title =" column modified successfully ", Details =" column modified successfully! " , DwellTime = 5, NavigationName = "column details", NavigationUrl = Url.Action ("ManageDetails", "Category", new {id = category.CategoryId})}; return RedirectToAction ("ManageNotice", "Prompt", _ n) } else {Error _ e = new Error {Title = "failed to modify the column", Details = "failed to save the column information to the database", Cause = "system error", Solution = Server.UrlEncode ("return to the column details page, contact the webmaster after modifying the information")}; return RedirectToAction ("ManageError", "Prompt", _ e);}}
Quite simply, the first step is to determine the column type, clear the extraneous data according to the column type, and then save the changes to the database.
Try to change "test column" to "company profile".
Saved successfully!
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.