vendredi 11 décembre 2015

How to bind modal data inside sidebar in _layout.cshtml in mvc3 EF5

I want to display modal data inside right sidebar in _layout.cshtml page, so the data will be display on every view. Here i create a PartialView for that data which i have placed inside rightsidebar in _layout. It works ok on index page, but when i redirect to another page, it gives me error. enter image description here

_layout.cshtml

    <div class="col-md-9 contentbar">
        @RenderBody()
    </div>
    <div class="col-md-3" style="padding-top: 20px;">

        <ul style="font-weight: bold; list-style-type: none; padding: 0px;">
            <li style="font-weight: bold;">Tv Serial Latest                   
                        @{Html.RenderPartial("ListAllTvt");}
            </li>
        </ul>
    </div>
</div> 

PartialView (ListAllTvt.cshtml)

@model  IEnumerable<Cmedia.Models.TVSerialModel>
<ul style="padding: 0; font-weight: normal; list-style-type: none;">
      @foreach (var item in Model)
      {
        <li>@Html.ActionLink(@item.Serial_Name, "ListAllEpisode", "TvSerialEpisode",new { id = item.Serial_ID}, null) </li>
      }
 </ul>

TvSerialContoller.cs

public class TvSerialController : Controller
{
    public ViewResult Index()
    {
       List<TVSerialModel> tv = tvContext.dbTvSerials.ToList();
       return View(tv);
    }

    public ActionResult Detail(Int32 id)
    {
       TVSerialModel tvserial = tvContext.dbTvSerials.Find(id);
        return View(tvserial);
    }

    public ActionResult ListAllTvSeri()
    {
       List<TVSerialModel> tv = tvContext.dbTvSerials.ToList();
       return View(tv);
    }
}

i guess when the index view called it set the model value by default because index and partialview using same model, but when i redirect to another page it flush the model data and then i get the error. I don't know how to fix this.

Aucun commentaire:

Enregistrer un commentaire