如何在主视图中渲染PartialView

时间:2016-07-13 10:07:11

标签: c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

heloo大家正在研究一个应用程序我的要求是在indexView中添加一个createView(到输入数据)(其中m显示来自数据库的表中的所有数据)从同一视图输入数据,CreateView已渲染没有任何问题,但错误诅咒回复错误="孩子 - 动作 - 不允许执行 - 重定向 - 动作",这是我的代码,看看你是否可以帮助.. 控制器代码

   // GET: /Brands/
    public async Task<ActionResult> Index()
    {
        return View(await db.Brands.ToListAsync());
    }
  // GET: /Brands/Create
    public ActionResult Create()
    {
        return PartialView("_Create", new BootstrapModalTest.Models.Brand());
    }

    // POST: /Brands/Create
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Create([Bind(Include="BrandId,BrandName,BrandCode")] Brand brand)
    {
        if (ModelState.IsValid)
        {
            db.Brands.Add(brand);
            await db.SaveChangesAsync();
            return PartialView("_Create", brand);
        }

        return PartialView("_Create", brand);
    }

,这是Index.cshtml查看代码..

div class="panel panel-primary">
<div class="panel-heading" style=" padding:2px 7px 0px 6px;"><h4>Frames</h4></div>

<div class="panel-body " style="padding:4px;">
    @{Html.RenderAction("Create", "Brands");}

</div>

<table class="table table-bordered>
//some data

1 个答案:

答案 0 :(得分:0)

尝试使用

@Html.Partial("../Controller/View", model)

@Html.Partial("~/Views/Controller/View.cshtml", model)

添加&#34; _Create&#34;的正确路径根据您的Create方法查看。 反过来,可以删除create方法。