0

How can I convert this to ASP.NET?

Or how can I convert ASP to Razor, what will I add or remove and what are the things to remember while converting ASP to Razor or reverse.

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PopulatingDDLusingEF.ViewModels.IndexViewModel>" %>
ssilas777
  • 9,672
  • 4
  • 45
  • 68

1 Answers1

0
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PopulatingDDLusingEF.ViewModels.IndexViewModel>" %>

In Razor you should use @Model keyword

@model PopulatingDDLusingEF.ViewModels.IndexViewModel
@{
    ViewBag.Title = "Result";
    Layout = "~/Views/Shared/Site.Master";   
}

This is an example how to convert ASP syntax to razor syntax which i got from Marcind's post

<% if(someCondition) { %>
  <ol>
  <% foreach(var item in Model) { %>
     <li><%: item.ToString() %></li>
  <% } %>
  </ol>
<% } %>

Can be expressed as follows in Razor:

@if(someCondition) {
   <ol>
   @foreach(var item in Model) {
      <li>@item.ToString()</li>
   }
   </ol>
}

Also check this for a quick useful Razor reference

Community
  • 1
  • 1
ssilas777
  • 9,672
  • 4
  • 45
  • 68
  • Thanks @ssilas777! Can you give me some good website/blogs that gives step by step tutorial learning MVC razor? –  Feb 19 '13 at 11:16
  • http://www.w3schools.com/aspnet/razor_intro.asp - For beginner this will do, i wouldn't recommend though – ssilas777 Feb 19 '13 at 11:23
  • I had been in W3Schools.com but I need some advancement, anyway Thanks again. –  Feb 19 '13 at 11:26
  • http://www.asp.net/web-pages/tutorials/basics/2-introduction-to-asp-net-web-programming-using-the-razor-syntax - Check this too – ssilas777 Feb 19 '13 at 12:29