0

I am trying to make a project on ASP.NET using .aspx pages. The project also contains .cshtml files that support razor syntax unlike .aspx pages. Now, I am fairly new to web programming and not very familiar with what could be an alternative to using razor syntax in .cshtml or if it is possible to just use .cshtml views with ASP.NET, thus, completely avoiding .aspx pages.

For example how do I implement this code (that works in .cshtml)

@AntiForgery.GetHtml()

In .aspx page

Following are more code examples that I want to implement in .aspx but cannot:

<div class="form-group">
    <label for="exampleInputEmail1" @if(!ModelState.IsValidField("email")) 
        { <text> class="error-label" </text> }>
        Email address
    </label>                    
    <input type="text" class="form-control" id="email" name="email" 
    value="@email" @Validation.For("email")/>
    @Html.ValidationMessage("email")
</div>
FawwazFaisal
  • 57
  • 2
  • 11

1 Answers1

1

It seems like your project is an ASP.NET MVC project with the mix between ASPX View Engine and Razor View Engine. Razor syntax and .cshtml are just parts of Razor View Engine whilst .aspx pages are of ASPX View Engine and both of them come from Web MVC framework. Of course, you could use .cshtml pages (Razor View) completely, it's just View Engine matter. But I'm not sure if you're familiar with MVC Pattern.

Kei Huynh
  • 29
  • 5
  • Thank you for the explanation. Yes I am familiar with the database first approach of MVC but I'm fairly new to classic ASP.NET. How can I achieve the goal of creating classes with .aspx.cs extension with web forms and using .cshtml instead of .aspx pages? – FawwazFaisal Apr 15 '19 at 11:02
  • 1
    I'm afraid that you can't. ASP.NET Web Forms is too different from ASP.NET MVC and ASP.NET Team hasn't had plant to support this. Already answered in this question: https://stackoverflow.com/questions/5264852/can-we-use-razor-syntax-in-asp-net-webforms-aspx-pages – Kei Huynh Apr 15 '19 at 15:03