I do have a following json in my MVC controller and I need to build a tabbed user interface dynamically from this json. What I need to achieve is something like in attached picture. I need to call few jquery functions upon clicking those dynamically generated
buttons. It would be great if someone can refer me the code for this.
public class MyTabs
{
[JsonProperty("Tabs")]
public Tab Tabs { get; set; }
}
public class Tab
{
[JsonProperty("Tab")]
public Section[] sections { get; set; }
}
public class Section
{
public string name { get; set; }
[JsonProperty("Widget")]
public WidgetItem[] Widget { get; set; }
}
public class WidgetItem
{
public int id { get; set; }
public string type { get; set; }
public string name { get; set; }
public string LinkedPin { get; set; }
}
2. Convert the json string to the Model data in controller:
public ActionResult Tab()
{
var tabs = new MyTabs();
//I store the json string in a local json file
using (StreamReader sr = new StreamReader(Server.MapPath("~/Content/tab.json")))
{
tabs = JsonConvert.DeserializeObject<MyTabs>(sr.ReadToEnd());
}
return View(tabs);
}
3. Pass the model to view and display it in view, bind click event to the buttons.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
163 Points
42 Posts
MVC dynamically generate Tabs and Content with JQuery support
May 31, 2017 04:30 AM|priyalwalpita|LINK
Hi,
I do have a following json in my MVC controller and I need to build a tabbed user interface dynamically from this json. What I need to achieve is something like in attached picture. I need to call few jquery functions upon clicking those dynamically generated buttons. It would be great if someone can refer me the code for this.
JSON in the Controller.
Image File Link : https://docs.google.com/uc?id=0B-Zcom9RVKUybkY4M3hWTkl2aVk
Thanks in advance
Contributor
6490 Points
2525 Posts
Re: MVC dynamically generate Tabs and Content with JQuery support
Jun 01, 2017 07:05 AM|Jean Sun|LINK
Hi priyalwalpita,
I use the following steps to do this:
1. Create some models based on the json string.
2. Convert the json string to the Model data in controller:
3. Pass the model to view and display it in view, bind click event to the buttons.
How it works on my side:
Best Regards,
Jean
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
163 Points
42 Posts
Re: MVC dynamically generate Tabs and Content with JQuery support
Jun 01, 2017 08:35 AM|priyalwalpita|LINK
Thanks a lot Jean ! I managed to run this perfectly :)