1

I've got a simple thing to do - implement the login form. My employer wants me to use Web forms and my stubborn ass want's to implement the MVC pattern (I already have). The problem is I have no idea how to instantiate the Controller. I run debugging, get the view, but since there is no controller (or model), nothing happens when I click login since no one can respond to the event.

Where and how can I instantiate the Controller?

2

1 Answer 1

1

Yes, you certainly can.

I quote: "As of 2014, the official answer to this problem is using Web API, as explained in this article I wrote for Simple Talk about a year ago.

Integrating a Web API layer into a Web Forms application couldn’t be easier. You just plug in the Web API runtime, configure routing so that you decide exactly which URLs you want to support and start writing your controller classes in the App_Code folder. Web API follows nearly the same programming model as ASP.NET MVC and is really easy to learn. In the end, it’s just like writing controller classes equipped with public methods callable from JavaScript clients.

ASP.NET Web Forms and ASP.NET MVC share the same runtime environment and requests are routed through exactly the same pipeline. It is even acceptable to say that ASP.NET MVC is just a global HTTP handler installed on the ASP.NET request pipeline. If the incoming request matches the URL requirements supported by the MVC handler then the request is routed to it; otherwise it is processed by the runtime as usual. “As usual” here means just as if it would go in a plain Web Forms application."

Here is the source of my above quoted information. I suggest you give this a read, as this is very useful and will give you a good understanding of the differences between both MVC and WebForms, and how can mix the architectures.

Sign up to request clarification or add additional context in comments.

3 Comments

Tnx, I'll look into Web API!
The article you gave me is a good intro into Web API, but it's too general (not too many useful info about HOW to deal with the problem, just "I've done it and it works")
Perfect. Now you have to take it on yourself to go and study/research how to implement WEB API. If you need any specific help, feel free to ask.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.