码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-11-08 01:13:56      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:.text   调试   file   rod   实例化   value   begin   comm   creat   

一。添加功能

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

 

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

标签:.text   调试   file   rod   实例化   value   begin   comm   creat   

原文地址:http://www.cnblogs.com/bfwbfw/p/6040858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!