Search Posts

Category: razor

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 asp.net 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 https://docs.angularjs.org/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, […]