一。添加功能
1.首先需要在前端显示界面View视图中添加
<div class="pull-right">
<a href="@Url.Action("Create")" class="btn btn-default">@T("添加")</a> </div>
2.控制器中呈现“添加”的界面:
public ActionResult Create()
{
///////添加权限的位置(如果需要的话)
var model = new EnterpriseInfoModel();//实例化所需的model
return View(model);
}
2.1对应的view:
@model NopEnterprise.Admin.Models.EnterpriseInfoModel//接收返回的model数据
@{
//page title
ViewBag.Title = T("添加企业信息").Text;
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="content-header clearfix">
<h1 class="pull-left">
@T("xxxxxxx")//标题位置(自行添加调试)
<small>@Html.ActionLink("(" + T("backToList") + ")", "List")</small>
</h1>
<div class="pull-right">
<input type="submit" name="save" class="btn btn-default" value="@T("Admin.Common.Save")" />
<input type="submit" name="save-continue" class="btn btn-default" value="@T("Admin.Common.SaveContinue")" />
</div>
</div>
@Html.Partial("_CreateOrUpdate", Model)
}
2.1.1
@using NopEnterprise.Admin.Models;
@model EnterpriseInfoModel
@using System.Text; @Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id) <script>
$(document).ready(function() {
bindBootstrapTabSelectEvent('enterprise-edit');
});
</script> <div class="content">
<div class="form-horizontal">
<div id="enterprise-edit" class="nav-tabs-custom">
<ul class="nav nav-tabs">
@Html.RenderBootstrapTabHeader("tab-info", @T("Admin.ContentManagement.Blog.BlogPosts.Info"), true)
</ul>
<div class="tab-content">
@Html.RenderBootstrapTabContent("tab-info", @TabInfo(), true)
</div>
</div>
</div>
</div> @{
//custom tabs
var eventMessage = new AdminTabStripCreated(this.Html, "enterprise-edit");
EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
foreach (var eventBlock in eventMessage.BlocksToRender)
{
@eventBlock
}
}
@{
//resources for product tags input
Html.AppendCssFileParts("~/Content/tagEditor/jquery.tag-editor.css");
Html.AppendScriptParts("~/Scripts/tagEditor/jquery.tag-editor.min.js");
Html.AppendScriptParts("~/Scripts/tagEditor/jquery.caret.min.js");
}
@helper TabInfo()
{
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-body"> <div class="form-group">
<div class="col-sm-3">
@Html.NopLabelFor(model => model.NoteTwo)
</div>
<div class="col-sm-9">
@Html.NopEditorFor(model => model.NoteTwo)
@Html.ValidationMessageFor(model => model.NoteTwo)
</div>
</div>
//多个并列div
</div>
</div>
</div>
}
3:控制器接收从view界面返回的请求并操作
[HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")]
public ActionResult Create(EnterpriseInfoModel model, bool continueEditing)
{ ///权限位置(需要时添加)if (ModelState.IsValid)
{
var enterprises = model.ToEntity();
_enterpriseInfoService.InsertEnterpriseInfo(enterprises);
//向表插入成功 SuccessNotification(_localizationService.GetResource("添加信息成功")); if (continueEditing)
{
return RedirectToAction("Edit", new { id = enterprises.Id });
}
return RedirectToAction("List");
}
return View(model);
}