Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 无法在视图内部渲染局部视图_Asp.net Mvc_Entity Framework - Fatal编程技术网

Asp.net mvc 无法在视图内部渲染局部视图

Asp.net mvc 无法在视图内部渲染局部视图,asp.net-mvc,entity-framework,Asp.net Mvc,Entity Framework,我的控制器 using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using C3CardKYC1.Models; namespace C3CardKYC1.Controllers { public class HomeController

我的控制器

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using C3CardKYC1.Models;

namespace C3CardKYC1.Controllers
{
    public class HomeControllerController : Controller
    {
        private ConnectionString db = new ConnectionString();

        //
        // GET: /HomeController/

        public ActionResult Index()
        {
            return View(db.DetailsEntries.ToList());
        }



        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /HomeController/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(DetailsEntry detailsentry)
        {
            if (ModelState.IsValid)
            {
                db.DetailsEntries.Add(detailsentry);
                db.SaveChanges();
                //return RedirectToAction("Index");
            }

            return View(detailsentry);
        }
       [HttpGet]
      public ActionResult displaydocument()
        {
            ViewBag.doctype = new SelectList(db.DocTypeMasters,"Id","DocTypeName");

            return PartialView();
           // return PartialView();
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}
这是我的创建视图代码

@model C3CardKYC1.Models.DetailsEntry

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>DetailsEntry</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.ClientId)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ClientId)
            @Html.ValidationMessageFor(model => model.ClientId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ClientName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ClientName)
            @Html.ValidationMessageFor(model => model.ClientName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EmployeeId)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EmployeeId)
            @Html.ValidationMessageFor(model => model.EmployeeId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EmpCitizenId)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EmpCitizenId)
            @Html.ValidationMessageFor(model => model.EmpCitizenId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EmpName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EmpName)
            @Html.ValidationMessageFor(model => model.EmpName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Nationality)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Nationality)
            @Html.ValidationMessageFor(model => model.Nationality)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DocumentType)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DocumentType)
            @Html.ValidationMessageFor(model => model.DocumentType)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@Html.Partial("displaydocument",Model)

我想生成一个视图create.cshtl。在里面,我想呈现displaydocumentview。我得到了这个错误。信息:没有“IEnumerable”类型的ViewData项具有键“DocTypeName”。

在离开控制器操作方法之前,您应该在
ViewBag
中定义
DocTypeName

ViewBag.DocTypeName = List<SelectListItem>()
{new SelectListItem("item1", 1), new SelectListItem("item2", 2)};
ViewBag.DocTypeName=List()
{新建SelectListItem(“item1”,1),新建SelectListItem(“item2”,2)};

我应该在哪里进行更改?因为您告诉计算机
@Html.DropDownList(“DocTypeName”,“Select”)
所以它需要
DocTypeName
来填充下拉列表。下面的错误是cmg键为“DocTypeName”的ViewData项的类型为“System.Collections.Generic.list`1[[System.Int32,mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]',但必须是“IEnumerable”类型。是的,我要填充下拉框,然后用您自己的
列表替换
new List()
ViewBag.DocTypeName = List<SelectListItem>()
{new SelectListItem("item1", 1), new SelectListItem("item2", 2)};