0

I have codes that are written and working fine as a Web Application with Codebehind file. However, I don't have the chance to convert my files to Web Application because customer wants the actual project as MVC so converting files is not enough to run the project. If I don't convert to application, it keeps given the error for my "txtUsername" and "txtPassword" does not exist in the current context.

I just need the modification to be done to make it work as in MVC logic.

under Views/login.aspx:

<%@ Page Language="C#" AutoEventWireup="True" Inherits="login" Codebehind="/Controllers/login.cs" %>

under Controllers/login.cs:

using System;
using System.Web.Security;
using System.Web.UI;

public partial class login : Page
{
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (Membership.ValidateUser(txtUsername.Text, txtPassword.Text))
        {
            FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
        }
    }
}

Even if I change my login.cs to have using System.Web.Mvc and public partial class login: ViewPage. It still gives me the error as "txtUsername" and "txtPassword" does not exist in the current context. I have many Web forms like this but it will be really helpful if somebody can help on how to change/move this login.aspx and login.cs from Web Forms approach to MVC approach and make them work fine without warning.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • so, do you have to convert the whole application OR add MVC to exsisting app? – lordkain Nov 18 '13 at 08:53
  • 6
    I don't believe it is anywhere as simple as you're imagining. You'd have to rewrite A LOT of code. – nphx Nov 18 '13 at 08:54
  • You have a LOT of reading to do on the differences between asp.net WebForms and MVC – Alex Nov 18 '13 at 08:58
  • @lordkain: People usually said the solution as "Convert to web application" but I dont have that chance because the Web project is opened as MVC. – user3002433 Nov 18 '13 at 08:58
  • @Alex: I was afraid I dont have any other chance too. Maybe somebody will any other opinion lets see... The worst thing is customer wants the MVC approach even I think we have a better logic and some other team already written codes as MVC so we don't have the chance to want from the customer to change the project back to Web Application. – user3002433 Nov 18 '13 at 09:02
  • There are quite a few references on SO about moving from WebForms to MVC, such as [this one](http://stackoverflow.com/a/571562/674700) or [this one](http://stackoverflow.com/a/8523029/674700). – Alex Filipovici Nov 18 '13 at 09:02
  • 2
    Why does the customer care about the tools you use? Do they also say you've got to use NHibernate instead of Entity Framework? Did the customer explicitly say _"Don't use WebForms, use MVC"_, or did you interpret another instruction as such? – CodeCaster Nov 18 '13 at 09:08
  • @CodeCaster: That seems funny right. We have our own logic under Business, CommonLibrary and Data layers. However, the customers tells us what to do even we told this would mess up with our whole idea. You know what they say "Customer is always right". So now we need additional time to convert everything on Web side to Mvc as Alex said and we don't have much time left now:) – user3002433 Nov 18 '13 at 09:18
  • Your customer doesn't sound right, but ill-informed. As if they think MVC is some silver bullet. If the project started in WebForms, it is (depending on the degree of completion of course) most likely better finished in WebForms. What reason did the customer give for changing the project's architecture? Do they and you understand this requires a rewrite of most of the pages? – CodeCaster Nov 18 '13 at 09:25
  • 2
    @CodeCaster: Sure we know it, we argued about this a lot. However, after some time they will be doing development within this project and as you say they think MVC is maybe more than a silver bullet. The reason is simple enough for them easy development with MVC but they are losing the benefits of our architecture even we told them not to use MVC. So as a conclusion we don't have a chance but change our code to MVC which seems to be taking lot of our time maybe this entire week. – user3002433 Nov 18 '13 at 09:35
  • MVC and WebForms, while not mutually exclusive, are very different achitectures. It will take a lot of knowledge and effort to rewrite this. – Tobberoth Nov 18 '13 at 13:44

0 Answers0