Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
<pre lang="C#">  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);
        }
    }
}


This is my create view code.

C#
@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)


this is my displaydocument view code

C#
@model C3CardKYC1.Models.DocTypeMaster

Select Document Type: @Html.DropDownList("DocTypeName", "Select");


C#
I want to generate one view create.cshtl. Inside that i want to render displaydocumentview. I am getting this error. information: There is no ViewData item of type 'IEnumerable' that has the key 'DocTypeName'.
Posted
Comments
Member 10624821 7-Jan-16 6:12am    
One of my view code is

@model C3CardKYC1.Models.DetailsEntry

@{
ViewBag.Title = "Create";
}

Create



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

<fieldset>
DetailsEntry

<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)
John C Rayan 7-Jan-16 7:21am    
@Html.DropDownList("DocTypeName", "Select"); should be @Html.DropDownList("doctype", "Select");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900