0

I need your help I have this app which was developed using MVC 1. now I'm supposed to upgrade this app to MVC 5. I have created anew MVC project and added the old project, fix old references and configuration. My problem is that I have a DropDownList server control which is not working. It suppose to reload the page according to the selected language, but it seems it's not getting the correct value and the default page is loaded. this is the code for my DropDownList. it's located in SiteBM.Master file

<asp:DropDownList runat="server" id="ddlLanguage" AutoPostBack="true"></asp:DropDownList>

this is the generated HTML for the working MVC1 project

<select name="ctl00$ddlLanguage" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ddlLanguage\',\'\')', 0)" id="ctl00_ddlLanguage">

and this is the generated HTML for the not working MVC5 project

<select name="ctl00$ddlLanguage" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ddlLanguage\',\'\')', 0)" id="ddlLanguage">

Please help!

Niladri
  • 5,832
  • 2
  • 23
  • 41
NDev
  • 9
  • 2
  • ASP.NET WebForms is not “ASP.NET MVC 1” - they’re radically different. You cannot really “upgrade” a web-application from WebForms to MVC - you will need to rearchitect your codebase to go from Page Code-behinds yo Controller Actions and introduce View-specific ViewModel types to represent the data that’s displaued. Additionally none of your “server controls” will work anymore because the ASPX View-engine is removed in MVC 5 (MVC Core) - you’ll need to rewrite then using Razor/cshtml. – Dai May 25 '18 at 18:19
  • my application was written using MVC and ASPX view engine, it's not a WebForms application. I'm trying to know if there is a way that I can configure my control to work properly as it was working before without rewrite the application from scratch. – NDev May 25 '18 at 19:24
  • 1
    The code in your first snippet is webforms (using `System.Web.UI` controls). It has nothing to do with MVC (and there is no such thing as `runat="server"` or `AutoPostBack="true"` in MVC). To generate a dropdownlist in MVC, you use the `@Html.DropDownListFor()` method - refer [this Q/A](https://stackoverflow.com/questions/34366305/the-viewdata-item-that-has-the-key-xxx-is-of-type-system-int32-but-must-be-o) for a typical example –  May 25 '18 at 22:03
  • This is an old code from MVC1 and it is in the SiteBM.Master file. If I'm going to use @Html.DropDownListFor() method how I can bind it. I'm kind new in this and need some help – NDev May 28 '18 at 12:46

0 Answers0