0

Need help here.

So I have this

@Html.DropDownListFor(m => m.Nationality, new SelectList(Model.NationalityList.Select(s => s.NationalityName)), "-- Please Select --")

Which shows the list of Nationality. I am just wondering how do I generate a table based on the selection nationality.

So for example I have something like

@if (Model.Nationality == "Japan")
{
Shows the code here for example another table
}

In ASP.NET Webform, when we select the DropDownlist, we can do autopostback and then generate the form below. How to do it in MVC Core?

Thanks

Sarah
  • 329
  • 5
  • 21
  • 1
    You use ajax to post the selected value to a method which returns a partial view (or `JsonResult`) of your table and update the DOM. –  Jan 22 '18 at 05:12
  • You will probably have to use an Ajax call to the server whenever a new select option gets selected. – Anthony McGrath Jan 22 '18 at 05:14
  • Autopostback in fact uses ajax call to render different values on same page, the same concept also available in MVC (you can pass values to action method using ajax call by adding parameters). – Tetsuya Yamamoto Jan 22 '18 at 05:35
  • Thank you so much guys. Looks like I need to learn AJAX now.Thanks – Sarah Jan 22 '18 at 10:28
  • Refer [this answer](https://stackoverflow.com/questions/29142422/rendering-partial-view-on-button-click-in-asp-net-mvc/29142790#29142790) for a typical example –  Jan 22 '18 at 22:51

0 Answers0