lundi 3 octobre 2016

how to use multiple partial view on a single View

I have A From and a grid in wich m showing the list of my custumers. so this isn't possible on a single view so i using partial view technique.So i created a form as parial view and a list with partial view. u can say these are two small boxes which now i want to place in a Big box means on the main view.Problem is when i run the Partial views separatly they work correctly but when i Bind them with Index View The list don't show the data otherwise on separate debug it works fine. but why not work when bind with index view.

Insert

This is the form Code

<label>Customer_Name</label>
<input type="text" id="Customer_Name" name="Customer_Name" />
<label>Customer_phone</label>
<input type="text" id="Customer_phone" name="Customer_phone" />
<label>Customer_Address</label>
<input type="text" id="Customer_Address" name="Customer_Address" />
<label>Customer_Email</label>
<input type="text" id="Customer_Email" name="Customer_Email" />
<label>Company_NTN</label>
<input type="text" id="Company_NTN" name="Company_NTN" />
<label>Country</label>
<input type="text" id="Country" name="Country" />
<label>Company_Name</label>
<input type="text" id="Company_Name" name="Company_Name" />

<div class="">
    <div class="">
        <input type="submit" value="Create" class="btn btn-default" />
    </div>     
</div>

This is Details Partial View

@model IEnumerable<WebApplication8.Models.Customer_Data>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
    <th>
        @Html.DisplayNameFor(model => model.Customer_ID)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Customer_Name)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Customer_phone)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Customer_Address)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Customer_Email)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Company_NTN)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Country)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Company_Name)
    </th>
    <th></th>
</tr>

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Customer_ID)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Customer_Name)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Customer_phone)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Customer_Address)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Customer_Email)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Company_NTN)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Country)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Company_Name)
    </td>

 </tr>
}

</table>

Now Controller

namespace WebApplication8.Controllers
{
public class DefaultController : Controller
{
 private Hisaab_ApplicationEntities hisaabetities = 
 new Hisaab_ApplicationEntities();

 **Here in Index i have created a View with no Model** 

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

    public ActionResult Insert(Customer_Data customerData)
    {
        hisaabetities.Customer_Data.Add(customerData);
        hisaabetities.SaveChanges();

        return RedirectToAction("Index");
    }

    public ActionResult Details()
    {   
        var model = new ViewModel();
        model.Customer_Data = hisaabetities.Customer_Data.ToList();
        return PartialView(model);
    }
}
}

Index View where I am Calling the Both Partial view the List and the Form

 @{
     ViewBag.Title = "Index";
     }

    <h2>Index</h2>

    @Html.Partial("~/Views/Default/Insert.cshtml")
    @Html.Partial("~/Views/Default/Details.cshtml",
    new List<WebApplication8.Models.Customer_Data>())

Aucun commentaire:

Enregistrer un commentaire