Skip to content

Show View into Another View And Insert both view At 1 click

Shakil Ahmed

Shakil Ahmed

Asked Nov 27, 2017, 12:31 AM EST1 answer
Share
LinkedInX
I am trying to add one view into another view and submit both at one click .pls give me a sample code in simple without using view model because foreach create problem for list data for view model

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Shakil Ahmed
    0
    i solve this right now ....i post this code for beginer as like me
    ---------------------------------------------------------------------------------
    controller
    -----------
     
    TypeScript
            // GET: itemEntries/Create
            public ActionResult Create()
            {
                List row = new List()
                {
                    new itemEntry(){IndentName=null,Remarks=null},
                    new itemEntry(){IndentName=null,Remarks=null},
                    new itemEntry(){IndentName=null,Remarks=null}
                };
                return View(row);
            }
    
            // POST: itemEntries/Create
    [HttpPost]
    [ValidateAntiForgeryToken]
    C#
            public ActionResult Create(List itemEntry, [Bind(Include = "IndentFormId,Sender,Receiver")] IndentFormTable indentFormTable)
            {
                if (ModelState.IsValid)
                {
                    db.IndentFormTables.Add(indentFormTable);
                    db.SaveChanges();
                    foreach (var i in itemEntry)
                    {
                        db.itemEntries.Add(i);
                        db.SaveChanges();
    
    
                    }
                    return RedirectToAction("Index");
                }
    
                return View(itemEntry);
            }
    --------------------------------
    view
    ---------------------------------
    @model IEnumerable
    Code
    @{
        ViewBag.Title = "Create";
    }

    Create

    @using (Html.BeginForm("Create", "itemEntries"))
    Code
    {
        @Html.AntiForgeryToken()
        var i = 0;
    itemEntry

    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    IndentName
    Remarks
    @foreach (var item in Model)
    Code
                {
    
    
    
    
    
    
    
    
                     i++;
    
                }
    
            ///another view i want to use in this view
           @{ Html.RenderAction("Create", "IndentFormTables"); }
    }
    @Html.ActionLink("Back to List", "Index")
    Code
    @section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
    }
    0