0

I have a view, with a list that i have populated. I want to have a DisplayFor that will change and show what is selected in the drop down list.

This is my view so far. I have tried googling the problem, and after a few hours of reading through pages i cant find anything specific to what i am trying.

<select id="Test1">
        <option value="test">Role1</option>
        <option value="test">Role2</option>
        <option value="test">Role3</option>
        <option value="test">Role4</option>
    </select>

    @Html.DisplayFor(Test1)

But of course this will just not work. And i really dont know what to try now. I tried using Test1.selected, and i also tried having Test1 as a model then pass a list through, but it would require a page to be refreshed.

Ryan white
  • 19
  • 8
  • 1
    `@Html.DisplayFor()` is razor code and its parsed on the server before its sent to the browser. If you want to respond to selecting and option, then you need to use javascript (and ajax to call a server method that returns a partial view based on the selected option so that you can update the DOM) –  Mar 14 '17 at 09:56
  • Oh ok, that actually makes sense. Is this difficult to achieve? – Ryan white Mar 14 '17 at 09:59
  • No. Refer [this answer](http://stackoverflow.com/questions/29142422/rendering-partial-view-on-button-click-in-asp-net-mvc/29142790#29142790) for an example. but do not handle the change event of the ` –  Mar 14 '17 at 10:01
  • You cannot do it with the built in Html.DisplayFor – Nag Mar 14 '17 at 10:11
  • Ok ill have a look thanks – Ryan white Mar 14 '17 at 10:26

0 Answers0