0

I'm facing a simple problem to render view within another view .Please help I have a controller and a view using a seperate model rendering dhtmlx scheduler(model is from a dll)

I need to place a listbox that is using a seperate model under the same view. I'm aware that a view is restricted to one model.So I'm confused how to bring my listbox in the sameview of the scheduler. This is my code:

Schedulercontroller.cs

Public Actionresult Index()
{

  var scheduler = new DHXScheduler();
...
code
...
return view(scheduler);

}

Index.cshtml

I placed _notes in location

Views/Scheduler/_notes



     <div id="dailynotesview">
              @*  @Url.Action("_notes","Scheduler");*@
              @*  @{Html.Partial("_notes","Scheduler");}*@
  @* @Html.Partial("../Shared/_Dailynote") *@
       @{Html.RenderAction("_notes","Scheduler");}
             </div>


     @Html.Raw(Model.GenerateLinks())

I tried using above methods in views to bring listbox in the same page, but I'm getting the error as follows. When I use @Html.Partial("../Shared/_notes") The model item passed into the dictionary is of type 'System.String', but this dictionary requires a model item of type 'Proj.Models.DashboardModel'.

  @Url.Action("_notes","Scheduler");  
    @{Html.RenderAction("_notes","Scheduler");}

I get no error also I don get to see listbox rendered too.I checked with inspect element too.

gs11111
  • 649
  • 2
  • 17
  • 49

1 Answers1

0

You can add List in your main model as follows,

public class ModelA
{
    // Model B Properties

    public IEnumerable<SelectListItem> YourList { get; set; }
}

Then in your view you can access it as follows

@foreach(var item in Model.YourList )
{

}
Jatin patil
  • 4,252
  • 1
  • 18
  • 27
  • my main model is a dll.i don have control over it. Please help – gs11111 Aug 26 '13 at 08:46
  • Then why dont you use viewdata to store your list. – Jatin patil Aug 26 '13 at 08:53
  • 1
    Have a look at my answer in http://stackoverflow.com/questions/17951524/mvc-and-entity-framework-select-list/17953161#17953161 – Jatin patil Aug 26 '13 at 08:55
  • I need to use this listbox in more than one place, i.e on a button click and in a tab menu.If i create a viewmodel, will it be possible to resuse? – gs11111 Aug 26 '13 at 11:52
  • In this case you can create separate model which will contain `GetList()` function which will return the list for you. then u can call this method from any action and can assign the result in viewdata `viewdata["list"] = GetList()` – Jatin patil Aug 26 '13 at 12:02