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

一。添加功能

 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);
        }

 

posted on 2016-11-07 22:01 WFaceBoss 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wfaceboss/p/6040858.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值