Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a model class as below:

public class Location
{
  public int LocationId {get; set;}
  public int LocationName {get; set;}
}
public class Load
{
  public string LoadId {get; set;}
  public string LoadName {get; set;}
  public List<Location> Locations {get; set;}
}


What i'm trying to accomplish is :
1. I need to give an index view, strongly typed by Load class
2. On the client side, Client hits a button, and an $.Ajax() function gets some JSON response from somewhere
3. I need to put this response, as items which go into the model : Model.Locations (which is a list)

What i'm having issues with:
When Jquery gets a reponse, i want to put the response into Model data.
1. This data, put into model (Model.Locations) should be a multiple select list
2. I've tried
@Html.ListBox("Locations",ViewBag.LocationsList as MultiSelectList)
After even trying to send Json Response to server, and trying to put the data into model there.

Anyway, i know the above thing is probably bad idea.

What i need is, I get the JSON response from somewhere, i need to send it to the server, have the server do some work, and then insert into a selectable list.

Can anyone point me in the right direction? would be great help. Thanks.

Again, the only issue here is: putting Jquery (Ajax/JSON) response into model data, where in after populating data, the list is multiselect list, and then the whole form can be submitted for processing.
Posted
Updated 29-Mar-12 11:57am
v3

1 solution

Hi,

This may not be a efficient way to do it, thought to share it.

Try loading data in viewdata in the get part of index, like below

C#
ViewData["CountryList"] = CountryList.ToSelectList();


and collect it back in the index page

HTML
<![CDATA[<% list = ViewData["CountryList"] as SelectList %>]]>


HTML
@Html.ListBox("Locations",list )

or

@Html.ListBox("Locations",ViewData["CountryList"] as SelectList)


Also, please find other solution here
http://stackoverflow.com/questions/5478936/need-help-in-html-listbox-in-asp-net-mvc[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900