Search Posts

Category: razor

How to render sections in using razor MVC view

I have a basic web site which is mixing cshtml content (note this is not an MVC site just a website serving up cshtml files) and angularJs. Default.cshtml is in the root of the site which references the _SiteLayout.cshtml file _SiteLayout contains the following html and razor syntax <!DOCTYPE html> <html lang=”en” ng-app=”app”> <head> <meta charset=”utf-8″ /> <title>@Page.Title</title> @RenderSection(“Styles”, false) <meta name=”viewport” content=”width=device-width” /> </head> <body> <div ng-view> @RenderBody() </div> <script src=”~/Scripts/angular.js”></script> <script src=”~/Scripts/ng-route.js”></script> <script […]

Gets Data in Json Format From AngularJs Controller

I am having a hard time with AngularJs. It works accordingly in some cases for me and when I try to change the template of the project, it doesn’t work anymore. Here is the scenario – I have a controller in ASP.NET MVC that returns the list of products in Json format and finally I call this controller using AngularJs controller as follows: C#: public JsonResult GetProducts() { var result = (from c in db.Products […]

Passing session object to angularjs function in razor view MVC

I need to pass the session object to a function that I call in ng-init. something like this; ng-init=initUser( @((User)Session[“userSession”]) ) I just want to pass my “User” object to the initUser method declared in angularjs. Is there a way to do it ?. I have searched for a solution and all are suggested to call an action method in the controller inside the “initUser” method and fetch the session object from the server […]

Data cannot be retrieved – AngularJS

I’ve a scenario where I’m fetching data from c# and want to show it on my cshtml view. Now the problem is although my Angular file (EditSingleRecord.js) is retrieving the list . I can’t fetch it in my cshtml(EditSingleRecord.cshtml). /// <reference path=”C:UsersDeepakdocumentsvisual studio 2015ProjectsEBazarEBazarScripts/angular-resource.min.js” /> (function() { //Create a Module var app = angular.module(‘MyApp’, []); // Will use [‘ng-Route’] when we will implement routing //Create a Controller app.controller(‘MYController’, function($scope, $http) { // here $scope is […]

Angularjs fails with passing data from ASP.Net Razor view

Recently I had a situation, when the user typed in input textbox something like “{{ text :}}” and saved it. And this caused the Angular fail on some pages. So, if I pass data to my controller from Razor view like this @{ var test = “{{ test :}}”; } <html> <head> </head> <body ng-app=”TestApp” ng-controller=”TestCtrl” ng-init=”test = ‘@test’;”> </body> </html> I get following error$parse/syntax?p0=:&p1=is%20an%20unexpected%20token&p2=6&p3=test%20:&p4=: Syntax Error: Token ‘:’ is an unexpected token at […]

How can Asp Net Core serve html static pages?

I start recently an Asp .Net Core app. Later i want to integrating it with Angular, but first i want a mechanism that will ‘replace’ cshtml with html. If i change extension from cshtml to html i get this ‘InvalidOperationException: The view ‘Index’ was not found’. Also i tried in Startup app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: “default”, template: “{controller=Home}/{action=Index}/{id?}”); }); but also didn’t work. Optional is to integrating cshtml layout content with html pages, […]