Pooja
Pooja

Reputation: 13

Can ASP.net pages be used in ASP.net MVC?

"You can use existing ASP.NET features with the ASP.NET MVC framework, such as nested master pages, in-line expressions (<%= %>), declarative server controls, templates, data-binding, localization, and so on." - MSDN

Does that mean we can use the server controls in ASP.net web forms in MVC?

Thanks,

Upvotes: 0

Views: 95

Answers (2)

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38683

Any controls that post back to the server don't work with MVC because MVC doesn't use the same mechanism or page cycle to post back to the same page. Rather MVC pages are routed to a new URL, so there's no concept of a 'persistant' page as there is with Web Forms.

There's a lot of discussion about how this sort of thing should be handled in an MVC framework because there's no doubt that Web Forms make many things very easy. Currently in MVC the closest thing to 'controls' are the Mvc HTML Helper classes that provide simple (but not very configurable) control rendering.

Using MVC vs. Web Forms is full of trade offs (in both directions) and there's no doubt you'll end up writing more markup code in MVC to make up for what you lose with Web Forms. The advantage is that you have much mroe control over rendering and aren't tied to the sometimes complex page pipeline cycle of postbacks.

Upvotes: 2

Soner Sevinc
Soner Sevinc

Reputation: 400

For Syntax,

Razor:

<ul>
@for (int i = 0; i < 10; i++) {
<li>@i</li>
}
</ul>

Web Form in mvc(You can use this too)

<ul>
<% for (int i = 0; i < 10; i++) { %>
<li><% =i %></li>
<% } %>
</ul> 

İf you want to check more information please check below link

hope helps you.

Using ASP.NET Server Controls in MVC?

Upvotes: 0

Related Questions