Visual Studio 2012 MVC 3 - Action button does not work

Asked

Viewed 652 times

2

I didn’t use the visual studio for a few years. Now I tried again and came across a problem.

I created a new web project in visual studio 2012, using the ASP.NET MVC 3 Web Application option. I asked for a new web form and put a Button and a Label on it. Hence the intention is, when clicking the button, to put any phrase on the Label.

To start, I clicked twice on the Button. Hence the visual studio has already created for me the function of the event Click on the button. Inside the event, I put the action:

Label1.Text = "Hello World";

It shows no errors, but when I run the project and click on the button, nothing happens. I never had this problem in previous versions of visual studio. In this version, and due to the MVC, there is something different I should do pro button perform the action when clicking on it???

  • You may not be running the latest build of your project. Try Click Build -> Clean Solution and try again.

  • 1

    Thanks Tony, but still it wasn’t. Really weird. Then I’ll try another PC to see if the problem can be here. Finding out what it is, I put it on. Thank you.

  • I was also surprised that he put the C# code inside the same ASPX (In page) document, and in previous versions, he placed the C# code in a separate class (Code Behind). It would be "force" to store the C# code in a separate file?

  • OK. You could leave by downloading Visual Studio 2013 (stable) http://www.visualstudio.com/pt-br/downloads/download-visual-studio-vs.aspx. Or if you prefer Visual Studio Vnext (in development).

  • I noticed that when I start a normal web application project (not MVC), then it works with Behind code, but when the project is MVC3.

  • Take advantage that you are resuming with Visual Studio and use a newer version like 2013.

  • Put in question the ASPX code and Code Behind

  • Guys, I installed VS 2013. But now when I try to run the project, the message appears: The display in '~/Views/Home/Index.aspx' should derive from Viewpage, Viewpage<Tmodel>, Viewusercontrol or Viewusercontrol<Tmodel>. Any hint???

  • Starts a new project, already with the new template that comes with Visual Studio 2013.

  • Now something occurred to me. I had VS 2012 before. But before installing 2013, I uninstalled 2012.

  • What happens is that MVC, as well as the internet itself, has evolved a lot and changed a lot throughout its versions. This is why it is recommended to use the latest version of Visual Studio and MVC.

  • Create a new project in VS 2013 and compare with yours and see what has changed in each of the files.

Show 7 more comments

1 answer

2


It won’t work, simply. MVC doesn’t use Code Behind. It’s another paradigm and another way to use buttons and pro events Controller. No point explaining all the differences in this answer.

On the wiki of the tag there are tutorials and documents you read to get started.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.