2

I'm working on ASP.NET MVC , My application is to display list of menues in list box and when you click on any items another view will display list of submenues , and I have a problem is how to return Json to another view in the first of all the controller return view model object to view to display it on list box like the following

  return View(data);

where data is array of Strings , and I add an event to list box when selecting some item

@Html.Orubase().ListBox("list").RenderMode(RenderMode.Auto).IOS(c => c.ShowCorners(false)).BindDataSource(Model, map =>
{
    map.MapTo<string>(binding =>
    {
        binding.ItemDataBound((item, nd) =>
        {
            item.Text = nd;
        });
    });
}).OnItemSelect("select")

Where select is javascript function that call another function in controller

function select(event, d) {
       var index = d.selectedItemIndex;

       $.ajax({
           url: '@Url.Action("GetSubMenue", "Home")',
           type: 'GET',
           dataType: 'json',
           data:{ind:index},
           cache: false,

           success: function (data) {

           }
       });

Now GetSubMenue function will return the following object "data" that is another array of string

   return Json(data,JsonRequestBehavior.AllowGet);

now I want GetSubMenue function to return Json data object to another view to view it in a new list so, can you help me please

3
  • you might want to rephrase this its difficult to understand what you are asking Commented May 10, 2013 at 4:51
  • to explain my problem in home view I have the following ajax in javascript , which called on some event function select(event, d) { $.ajax({ url: '@Url.Action("GetSubMenues", "Home")', type: 'GET', dataType: 'json', data:{ind:index}, cache: false, success: function () { } }); and in home controller public ActionResult GetSubMenues(int ind) { List<string> data = new List<string>(new string[10]); for (int i=0;i<size;i++) { // assign value to data } now how can I pass data object from this controller to another view called SubMenue with data object in view model Commented May 10, 2013 at 5:34
  • 2
    please edit your original question its useless posting code in the comments Commented May 10, 2013 at 5:39

1 Answer 1

0

You may want to look at jquery templates. You can render a template out with your main view and then when you retrieve your sub menu populate the template with the json data.

Alternatively you could return a PartialView from the ajax call and manually replace the html in the document.

Sign up to request clarification or add additional context in comments.

2 Comments

jquery templates has been suspended more than 1 year ago. I would suggest an alternative. I use handlebars which works great and has good performances.
thank Daneil and Leftyx for response , I used PartialView and it succeeded for view data but in the same view but I want to show the data in the new View, I tried to "return View" but it did't gave me any output , so can you help me to switch to new view please

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.