Showing posts with label mvc. Show all posts
Showing posts with label mvc. Show all posts

Friday, September 20, 2019

Dot Net CORE Tips

(1) Razor Pages: For dotnet core application, we can have advantage of building Razor Pages just like we have ".axpx" pages in traditional web application. But there is also an added advantage of MVC pattern can be implemented with existing structure.

(2) Microsoft.Windows.Compatibility: This package is essential whenever we are performing any operation which is available in .net framework implementation.
for e.g. dataSet.Tables[0].AsEnumerable() - This functionality will not available until you will not add above package. As this is dot net native functionality and to laverage this we need this package support. There are many other functionalities are still there.

(3) File Operation: To perform file operation in web, we have practices of using Server.MapPath(filepath) to work with files. But with dotnet core web app this operation is replace with below
private IHostingEnvironment _env;

public MyController(IHostingEnvironment env)
        {
            _env = env;
        }
var webRoot = _env.WebRootPath;

Now, here _env.webRootPath will be your application wwwroot folder path and here you can perform your operation of saving/sp-net-core
- https://gunnarpeipman.com/aspnet/aspnet-core-content-web-root/
- https://www.mikesdotnetting.com/article/302/server-mappath-equivalent-in-asp-net-core
- https://stackoverflow.com/questions/43992261/how-to-get-absolute-path-in-asp-net-core-alternative-way-for-server-mappath

(4) Upload/Save Image
- https://www.codeproject.com/Tips/4051593/How-to-Upload-Images-on-an-ASP-NET-Core-2-2-MVC-We
- https://stackoverflow.com/questions/42741170/how-to-save-images-to-database-using-asp-net-core

(5) To get all the output in json with no case applied on output of json result, in this case just add below line of code to Startup.cs file under ConfigureServices function.
services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

(6) To work with tag helpers below package to install
Microsoft.AspNetCore.Razor.Runtime

(7) To work with sessions user below package 
Microsoft.AspNetCore.Session

(8) Cookie Authentication
https://www.c-sharpcorner.com/article/cookie-authentication-with-asp-net-core-2-0/

(9) StaticFiles: to work with static files like images, html, js files use below  package
Microsoft.AspNet.StaticFiles

(10) It gives us access to the assemblies and classes provided by the framework.
Microsoft.AspNet.Mvc

(11) to build bundle files for css/js use below package
BuildBundlerMinifier
(1) https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BundlerMinifier
(2) https://www.c-sharpcorner.com/article/bundling-and-minifying-in-asp-net-core-applications/
(3) https://docs.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-2.2&tabs=visual-studio

(12) When there is issue of tag is not properly rendered
- In this case, check with Taghelper is added to _ViewImport.cshtml page or not, if not then add like below
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
- https://github.com/aspnet/AspNetCore/issues/534


Thursday, May 7, 2015

Working with Export to PDF in Kendo Grid

Here is some link to work with export to PDF in kendo grid

(A) PDF Export Demo: Export to PDF demo and documentation link 
(1) Grid / Export to PDF

(2) Walkthrough of the Grid Features and Behavior

(B) Kendo UI Export Options with Customizations: Export to PDF functionality in two different way you want to manipulate
(1) Kendo UI Drawing API Export functionality - Document Export

(2) Kendo UI PDF Export customizations - Page Layout

(C) Kendo Grid Export to PDF: Export to PDF with launcher which lets user to ask user if we export then it will ask user with open/save dialog
(1) Kendo UI Grid Export to Excel / PDF not working on IE9

(2) Kendo Grid Configuration for Export

Monday, August 4, 2014

Error : Service data not get refresh in IE8 from Client Side

I face problem of Data not refresh from client side when we are working with IE. I found this problem while i am working with IE8 and above.

Problem is like, in my MVC Single Page Application, when we are fetching any data from client side for first time it will get data perfectly but subsequent call for same data or some back and forth to some other location give me previous unchanged data which are cached. But, after a bit of googling following line of code works for me and resolved my problem.



This line of code i put in "_layout.cshtml" header section and it works for me and then after it gives me refreshed data view.


The above line of code works fine for me and resolved my problem.

Thursday, February 20, 2014

Error : CSS, Images not loading when Debub="false" in web.config for MVC Application

For MVC application, i came across problem while i set Debut="false" in web.config file and ultimately css and images not loading from BundleConfig file but when i set it to "true" will load all files.

While googling i got some Web.Config settings shown below, modify your web.config in the system.webServer section to run these requests through the BundleModule


But, this line of code for Web.Config not solved my problem. Finally, i got to know about bundle name in BundleConfig file, i chnaged it shown below.

- Before Change Path :
"~/Content/css" : My all CSS were reside under "Content/css"
- After Change:
"~/Content/css/css"

So, to get rid of the problem you need to give path exactly as per project and put extra "css" after it will resolve your problem for CSS not loading.

Monday, August 5, 2013

Working with Macro Parameter In Umbraco CMS

In your Partial View, if we are passing parameters then to fetch/pass value to parameters we can use following way.

code
:var data = Model.MacroParameters;

description: This will fetch the Macro Parameter associated with our partial view. This line of code are placed in your partial view.

Now, to fetch value of your paremeter value use following line of code
string Name = data.FirstOrDefault(c => c.Key == "ParameterName").Value.ToString(); 

"ParameterName" is the name of your parameter/property which is defined in partial view.

This will fetch value passed to parameter in your partial view and you can use this value to your internal function.                  



Monday, July 29, 2013

Working with Media Items in Umbraco CMS

Different ways of  fetching media items in Umbraco CMS
Following are some different ways of fetching Media items in Umbraco CMS.

(1) To get media by id user following line of code
code : var varMedia = new umbraco.cms.businesslogic.media.Media(1);
description: This will fetch details of the media item by its id, in above code item 1 is some media item and based on this id we can find details of this media file.
-- to get file value use following line of code, in this code "umbracoFile" is the name of the property which contains name of the file
var file = varMedia.getProperty("umbracoFile");
further, you can get value by following line item
string filename = (string)file.Value


(2) To get file placed at root location on Media
code: var media = Services.MediaService.GetRootMedia().FirstOrDefault(c => c.Name == "filename");
description: This line of code will get specified file in rootmedia
-- to get file value user following line of code
string filename = media.Properties["umbracoFile"].Value.ToString()

(3) To get all files of a folder in Media
-- First, fetch id of the media folder using following line of code
var media = Services.MediaService.GetRootMedia().Where(c => c.Name == "foldername").FirstOrDefault();
- You can also check here that the item that we found is file or folder using following line of code
media.ContentType.Alias == "Folder"
-- Get if of the folder
int ID = media.Id;
-- following line of code will get all childrens/subfiles of the specified folder id. 
IEnumerable mediaChildList = Services.MediaService.GetChildren(ID);
You can loop through the child items of folder and can get specific file details

(4) To get file name using umbraco namespace on Partial View.
This line of code coulde be written on partial view.

code: var rootNode = new Node(-1).Children;
var Mainlist = ((Node)(rootNode[0])).ChildrenAsList.FirstOrDefault(c => c.Name == "foldername");

description: above line of code will get root node with given folder name
-- to get a file from above line of code
var DetailList = Mainlist.ChildrenAsList.FirstOrDefault(c => c.Name == "filename");
-- using following line of code we can get url of the file name

var src = Umbraco.Media(Convert.ToInt32(@DetailList.GetProperty("thumbnail").Value)).umbracoFile;

(5) To get file name using umbraco namespace on Partial View with other way. 
code: var rootNode = new Node(-1).ChildrenAsList.FirstOrDefault(c => c.Name == "foldername");
description: above line of code will fetch folder with name specified
-- to get child items of the folder use following line of code
var list = rootNode.ChildrenAsList;
-- to get url of the file in above folder loop through the all items in list and if file name matches, use following line of code

@node.NiceUrl

We can also get first node of the Media using following line of code code:rootNode = new Node(-1).Children;
List list = rootNode[0].ChildrenAsList;
description: above line of code will get files from first node and fetches child items from this node.       

       


Tuesday, December 21, 2010

Working with MVC

Here is some links about MVC.
==> MVC 1.0
(1) ASP.NET MVC Framework - ScottGu's Blog

(2) ASP.NET MVC Framework (Part 1) - ScottGu's Blog

(3) ASP.NET MVC Framework (Part 2): URL Routing - ScottGu's Blog

(4) ASP.NET MVC Framework (Part 3): Passing ViewData from Controllers to Views - ScottGu's Blog

(5) ASP.NET MVC Framework (Part 4): Handling Form Edit and Post Scenarios - ScottGu's Blog
(6) ASP.NET MVC Framework Road-Map Update
(7) Free ASP.NET MVC “NerdDinner” Tutorial Now in HTML - ScottGu's Blog

(8) ASP.NET MVC 1.0 - ScottGu's Blog

(9) Download details: ASP.NET MVC 1.0

(10) Upgrading an ASP.NET MVC 1.0 Application to ASP.NET MVC 2: The Official Microsoft ASP.NET Site

(11) ASP.NET MVC Source Code Now Available - ScottGu's Blog

==> MVC 2
(1) ASP.NET MVC 2 Released - ScottGu's Blog

(2) ASP.NET MVC 2 - ScottGu's Blog

(3) ASP.NET MVC 2: Strongly Typed Html Helpers - ScottGu's Blog

(4) ASP.NET MVC 2: Model Validation - ScottGu's Blog

(5) What’s New in ASP.NET MVC 2: The Official Microsoft ASP.NET Site

(6) Download details: ASP.NET MVC 2 RC

(7) Localizing ASP.NET MVC Validation

==> MVC 3

(1) Introducing ASP.NET MVC 3 (Preview 1) - ScottGu's Blog

(2) Download details: ASP.NET MVC 3 RC2

(3) Download details: ASP.NET MVC 3 Release Candidate

(4) Brad Wilson: ASP.NET MVC 3 Service Location, Part 1: Introduction

(5) HTML5 Improvements with the ASP.NET MVC 3 Tools Update

(6) EF Code First and Data Scaffolding with the ASP.NET MVC 3 Tools Update

(7) ASP.NET MVC 3 Tools Update
   
     Introducing Razor
     (1) Introducing Razor

     (2) New @model keyword in Razor 

     (3) Layouts with Razor

     (4) Server-Side Comments with Razor

     (5) Razor’s @: and syntax

     (6) Implicit and Explicit code nuggets with Razor

     (7) ASP.NET MVC 3: Layouts and Sections with Razor

     (8) ASP.NET MVC 3 and the @helper syntax within Razor