Sunday, May 19, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  67] [ 4]  / answers: 1 / hits: 27362  / 10 Years ago, thu, september 11, 2014, 12:00:00

I am working on a MVC 5 project. When I use a html page at my views, it load that page but when I use .cshtml page it is not loading the view. The Blank page appears.



$urlRouterProvider
.otherwise('/app/dashboard');

$stateProvider
.state('app', {
abstract: true,
url: '/app',
templateUrl: 'tpl/app.html'
})
.state('app.dashboard', {
url: '/dashboard',
templateUrl: 'tpl/app_dashboard.html'
})


Please guide me how to use cshtml file or the best way to do it.


More From » c#

 Answers
5

Yes, you can.



Adding a similar answer to Yasser's, but using ngRoute:



1) Instead of referencing your partial HTML, you need to reference a Controller/Action to your ASP.NET MVC app.



.when('/order', {
templateUrl: '/Order/Create',
controller: 'ngOrderController' // Angular Controller
})


2) Your ASP.NET MVC will return a .cshtml view:



public class OrderController : Controller
{
public ActionResult Create()
{
var model = new MyModel();
model.Test= xyz;

return View(MyView, model);
}
}


3) Your MyView.cshtml will mix Razor and Angular. Attention: as its a partial for your Angular app, set the layout as null.



@model MyProject.MyModel

@{
Layout = null;
}

<h1>{{ Test }}</h1> <!-- Angular -->
<h1>Model.Test</h1> <!-- Razor -->

[#69494] Tuesday, September 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;