Using C# object in Javascript in ASP.NET MVC

  1. Using @Html.Raw():
    dosomething(‘@Html.Raw(Model.UrProperty)’);
  2. Using JavaScriptSerializer() in the model:

Continue reading

Advertisements

How to use AngularJS in ASP.NET MVC and Entity Framework

This post is taken from Dhananjay Kumar.

In short, this post will touch upon:

  • adding an AngularJS library in ASP.NET MVC;
  • reference of AngularJS, bundling and minification;
  • fetching data using the Entity Framework database;
  • returning JSON data from an ASP.NET controller;
  • consuming JSON data in an AngularJS service;
  • using AngularJS service in AngularJS controller to pass data to the view; and
  • rendering data on an AngularJS View

Continue reading

Client Browser’s Submit Mechanism And The Postback Mechanism in ASP.NET and How the server knows which button clicked

While reading about “UseSubmitBehavior in an asp.net button”, I came to know that UseSubmitBehavior property to specify whether a Button control uses the client browser’s submit mechanism or the ASP.NET postback mechanism. By default the value of this property is true, causing the Button control to use the browser’s submit mechanism. If you specify false, the ASP.NET page framework adds client-side script to the page to post the form to the server. (causes the button to use the ASP.NET postback mechanism, also to identify at server side which button was clicked in the browser.). Continue reading

Numbers as keys in JSON object

JSON object: 
var jsonParams = {
                Name: ‘ram’,
                    1: ‘asdf’,
                     2: ‘2312’
}
 
If you want to read value from above JSON object
 
$(“#Name”).val(jsonParams.Name);
$(“#Street”). val(jsonParams[“1”]);
$(“#Pin”).val(jsonParams[“2”]);

Fill drop down list based on selection of another drop down list in ASP.NET MVC

Model:

namespace MvcApplicationrazor.Models
{
    public class CountryModel
    {
        public List<State> StateModel { get; set; }
        public SelectList FilteredCity { get; set; }
    }
    public class State
    {
        public int Id { get; set; }
        public string StateName { get; set; }
    }
    public class City
    {
        public int Id { get; set; }
        public int StateId { get; set; }
        public string CityName { get; set; }
    }
}   

Continue reading

ActiveX control and using it in Javascript & Vbscript to add key value in the Registry.

ActiveX is a client-side technology only. It is designed to allow COM objects registered on the client machine to be instantiated in the browser. ActiveX controls can be used in clientside applications running in a web browser. When the user accesses a web page, the control is downloaded to the client machine and is run from the browser using a scripting language such as Javascript or VBScript. Continue reading