asp.net mvc - MVC Partial View throwing error on dropdownfor -


i have partial view want display search interface. every time tells me error

there no viewdata item of type ienumerable has key resource_type_id.

i have tried many things make work nothing helps.

this view calls partialview

@model ienumerable<newsamacentral2._0.viewmodel.memberresourcesviewmodel.memberresource> @{     viewbag.title = "add resource folder"; } <h2>add resource folder</h2> <div>     @{html.partial("searchresource", new newsamacentral2._0.viewmodel.memberresourcesviewmodel.resourcesearch());} </div> @using (ajax.beginform("insertattendee", "meetings", new ajaxoptions  { httpmethod = "post" })) {     if (model.any())     {     } } 

this partialview

@model newsamacentral2._0.viewmodel.memberresourcesviewmodel.resourcesearch @using (ajax.beginform("addattendee", "meetings", new ajaxoptions { updatetargetid = "addattendee", httpmethod = "post" })) {     <div class="form-group">         <label for="keyword">keyword(s): </label>@html.textbox("keyword", null, new { @class = "form-control" })     </div>     <div class="form-group">        @html.labelfor(model => model.resource_type_id)         @html.dropdownlistfor(model => model.resource_type_id, model.resource_type, "-- select --", new { @class = "form-control" })     </div>     <div class="form-group">         <label for="author">author(s): </label>@html.textbox("author", null, new { @class = "form-control" })     </div>       <div class="form-group">         <input type="submit" name="submit" value="search" />     </div> } 

this controller never seems called...

public partialviewresult searchresource() {     var results = new memberresourcesviewmodel.resourcesearch();     results.resource_type = db.resource_types.select(s => new selectlistitem     {         text = s.name,         value = s.id.tostring()     }).distinct().orderby(x => x.text);     return partialview(results); } 

this viewmodel

namespace newsamacentral2._0.viewmodel {     public class memberresourcesviewmodel     {         public ienumerable<memberresource> memberresourceresult;         public memberresource memberresource;          public class memberresource         {             public resourcesearch resource_search { get; set; }             [key]             public int id { get; set; }             [displayname("resource title")]             public string title { get; set; }             public ienumerable<selectlistitem> resource_type { get; set; }             [displayname("resource type")]             public string resource_type_id { get; set; }             [displayname("keyword")]             public string keyword { get; set; }             [displayname("author")]             public string author { get; set; }             [displayname("subject type")]             public string subject_type { get; set; }             [displayname("industry")]             public string industry { get; set; }             [displayname("description")]             public string description { get; set; }         }          public class resourcesearch         {             [displayname("author")]             public string author { get; set; }             public ienumerable<selectlistitem> resource_type { get; set; }             [displayname("resource type")]             public string resource_type_id { get; set; }             [displayname("keyword")]             public string keyword { get; set; }         }     } } 

you have carefull capital letters , put model not model:

@html.labelfor(model => model.resource_type_id) @html.dropdownlistfor(model => model.resource_type_id, model.resource_type, "-- select --", new { @class = "form-control" }) 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -