Click here to Skip to main content
15,905,963 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionMVC Controller Question Pin
TheOnlyRealTodd19-Jul-16 18:19
professionalTheOnlyRealTodd19-Jul-16 18:19 
AnswerRe: MVC Controller Question Pin
F-ES Sitecore20-Jul-16 0:13
professionalF-ES Sitecore20-Jul-16 0:13 
GeneralRe: MVC Controller Question Pin
TheOnlyRealTodd22-Jul-16 16:57
professionalTheOnlyRealTodd22-Jul-16 16:57 
QuestionMVC Model Binding Pin
MadDashCoder19-Jul-16 6:31
MadDashCoder19-Jul-16 6:31 
AnswerRe: MVC Model Binding Pin
Richard Deeming19-Jul-16 8:01
mveRichard Deeming19-Jul-16 8:01 
GeneralRe: MVC Model Binding Pin
MadDashCoder19-Jul-16 19:47
MadDashCoder19-Jul-16 19:47 
AnswerRe: MVC Model Binding Pin
F-ES Sitecore20-Jul-16 0:01
professionalF-ES Sitecore20-Jul-16 0:01 
GeneralRe: MVC Model Binding Pin
MadDashCoder20-Jul-16 7:12
MadDashCoder20-Jul-16 7:12 
Thank you so much for replying. I see what you are trying to do, unfortunately its not working for me since my situation is a little different than what you've posted above.

Below is a snippet of the MerchandiseServiceClient class definition inside of the Models folder
C#
public class MerchandiseServiceClient
{
       private string BaseURL = "http://localhost:14000/MerchandiseService.svc/";
       public Merchandise FindMerchandiseByID(string id)
       {
           try
           {
               var webClient = new WebClient();
               string url = string.Format(BaseURL + "FindMerchandiseByID/{0}", id);
               var javascriptSerializer = new JavaScriptSerializer();
               return javascriptserializer.Deserialize<Merchandise>(jsn);
           }
           catch
           {
               return null;
           }
       }

       public List<Category> FindAllCategories()
       {
           try
           {
               var webClient = new WebClient();
               var jsn = webClient.DownloadString(BaseURL + "FindAllCategories");
               var javascriptSerializer = new JavaScriptSerializer();
               return javascriptSerializer.Deserialize<List<Category>>(jsn);
           }
           catch
           {
               return null;
           }
       }
       .
       .
       .
       .
}

The MerchandiseServiceClient class is one of many classes in the Models folder. The FindAllCategories() method of the MerchandiseServiceClient class gets JSON data from a RESTful WCF service and it returns a List of Category objects.

I tried to use this List of Category objects to populate the dropdownlist but it is not working. Please see my code below.

MerchandiseController
C#
[HttpGet]
public ActionResult Edit(string id)
{
  MerchandiseServiceClient msc = new MerchandiseServiceClient();  
  ViewBag.categoryList = msc.FindAllCategories();
          
  MerchandiseViewModel mvm = new MerchandiseViewModel();
  mvm.Merchandise = msc.FindMerchandiseByID(id);
            
  return View("Edit", mvm);   
}

Edit View
<tr>
 <td>@Html.LabelFor(model=>model.Category.ID, "Category")</td>
 <td> @Html.DropDownListFor(model => model.Category.ID, (SelectList)ViewBag.categoryList, "Select A Category")</td>  
</tr>


modified 21-Jul-16 11:35am.

GeneralRe: MVC Model Binding Pin
F-ES Sitecore20-Jul-16 22:10
professionalF-ES Sitecore20-Jul-16 22:10 
AnswerRe: MVC Model Binding Pin
jkirkerx3-Aug-16 8:01
professionaljkirkerx3-Aug-16 8:01 
QuestionMessage Closed Pin
18-Jul-16 14:50
MadDashCoder18-Jul-16 14:50 
AnswerRe: Switching From Textbox To Dropdownlistbox Pin
Richard Deeming19-Jul-16 2:04
mveRichard Deeming19-Jul-16 2:04 
Questionasp.net Pin
Member 1263882918-Jul-16 5:41
Member 1263882918-Jul-16 5:41 
QuestionRe: asp.net Pin
ZurdoDev18-Jul-16 5:58
professionalZurdoDev18-Jul-16 5:58 
AnswerRe: asp.net Pin
jkirkerx3-Aug-16 8:11
professionaljkirkerx3-Aug-16 8:11 
QuestionSetup for a web application Pin
Member 1027267614-Jul-16 3:11
professionalMember 1027267614-Jul-16 3:11 
AnswerRe: Setup for a web application Pin
koolprasad200314-Jul-16 18:30
professionalkoolprasad200314-Jul-16 18:30 
AnswerRe: Setup for a web application Pin
John C Rayan18-Jul-16 2:03
professionalJohn C Rayan18-Jul-16 2:03 
QuestionWhat's new in ASP.NET? Pin
Piya2713-Jul-16 19:08
Piya2713-Jul-16 19:08 
AnswerRe: What's new in ASP.NET? Pin
Richard MacCutchan13-Jul-16 21:52
mveRichard MacCutchan13-Jul-16 21:52 
AnswerRe: What's new in ASP.NET? Pin
ZurdoDev14-Jul-16 5:11
professionalZurdoDev14-Jul-16 5:11 
AnswerRe: What's new in ASP.NET? Pin
koolprasad200314-Jul-16 18:25
professionalkoolprasad200314-Jul-16 18:25 
AnswerRe: What's new in ASP.NET? Pin
John C Rayan18-Jul-16 2:05
professionalJohn C Rayan18-Jul-16 2:05 
AnswerRe: What's new in ASP.NET? Pin
petter201231-Aug-16 14:12
petter201231-Aug-16 14:12 
Questionwhat datasource control to use on a web from 2010 Pin
dcof12-Jul-16 11:58
dcof12-Jul-16 11:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.