框架的 总结(nop)------添加功能

2019-04-08 11:43:42 浏览数 (1)

一。添加功能

 1.首先需要在前端显示界面View视图中添加

代码语言:javascript复制
 <div class="pull-right">

  <a href="@Url.Action("Create")" class="btn btn-default">@T("添加")</a>
     
</div>

2.控制器中呈现“添加”的界面:

代码语言:javascript复制
 public ActionResult Create()
        {
///////添加权限的位置(如果需要的话)
            var model = new EnterpriseInfoModel();//实例化所需的model
            return View(model);
     }
2.1对应的view:

 2.1.1

代码语言:javascript复制
@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界面返回的请求并操作

代码语言:javascript复制
    [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);
        }

0 人点赞