Skip to content

Instantly share code, notes, and snippets.

View sphingu's full-sized avatar
:dependabot:
Focusing

Sumit Hingu sphingu

:dependabot:
Focusing
View GitHub Profile
@sphingu
sphingu / anotherThumbnail.cs
Last active December 18, 2015 13:08
Generate Image Thumbnail
//File Upload
// If file field isn’t empty
if (filUpload.PostedFile != null)
{
// Check file size (mustn’t be 0)
HttpPostedFile myFile = filUpload.PostedFile;
int nFileLen = myFile.ContentLength;
@sphingu
sphingu / readXML.cs
Created June 15, 2013 07:53
Read Xml and bind to GridView
DataSet ds = new DataSet();
ds.ReadXml(MapPath("MyXML.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
@sphingu
sphingu / ReadableFileSize.cs
Created June 15, 2013 08:13
Readable File Size
public static String readableFileSized(long size)
{
long bytes = size;
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB" };
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
string readable = num.ToString() + suf[place];
return readable;
}
@sphingu
sphingu / GetRealErrors.cs
Created June 18, 2013 09:33
How To See Validation Errors Details in MVC
// Get the Real error off the ModelState
var errors = GetRealErrors(ModelState);
private IEnumerable<ModelError> GetRealErrors(IEnumerable<KeyValuePair<string, ModelState>> modelStateDictionary)
{
var errorMessages = new List<ModelError>();
foreach (var keyValuePair in modelStateDictionary)
{
if (keyValuePair.Value.Errors.Count > 0)
{
@sphingu
sphingu / MVC_WebGrid.rb
Created June 18, 2013 13:30
WebGrid in MVC
@{
var grid = new WebGrid(Model.Select((item, index) => new { Index = index+1, Element = item }), defaultSort: "First Name", canSort: true, canPage: true, rowsPerPage: ViewBag.PageSize, ajaxUpdateContainerId: "grid");
}
@grid.GetHtml(htmlAttributes: new { id = "grid" }, fillEmptyRows: false, tableStyle: "webGrid", headerStyle: "header", footerStyle: "footer", rowStyle: "rowcss", alternatingRowStyle: "alterrowcss",
selectedRowStyle: "selectedRow",
columns: grid.Columns(
grid.Column(columnName: "Index", header: "Sr No."),
grid.Column("Element.strSurnameEN", "Name", @<text><i data-val='@item.Element.ID'>@Convert.ToString(item.Element.strSurnameEN + " " + item.Element.strNameEN + " " + item.Element.strRelativeEN)</i></text> ),
grid.Column("Element.dtDOB", "DOB", item => item.Element.dtDOB != null ? item.Element.dtDOB.ToString("dd/MM/yyyy") : ""),
gri
@sphingu
sphingu / HtmlPrefixScopeExtensions.cs
Last active December 18, 2015 15:39
Using Same Model for Multiple times in one View using @Html.BeginCollectionItem
using System;
using System.Web.Mvc;
using System.Web;
using System.Collections.Generic;
namespace NPS.Helpers
{
public static class HtmlPrefixScopeExtensions
{
private const string idsToReuseKey = "__htmlPrefixScopeExtensions_IdsToReuse_";
@sphingu
sphingu / PositiveInteger.js
Created June 18, 2013 13:46
Only Positive Integer allow in Textbox using JQuery
$(".positive-integer").numeric({ decimal: false, negative: false }, function () { alert("Positive integers only"); this.value = ""; this.focus(); });
@sphingu
sphingu / Multiple_File_Upload.cs
Last active December 18, 2015 15:39
Multiple File Upload in MVC
http://www.mindstick.com/Articles/518b07f7-3fc8-4b86-8ab9-cab49ecb001a/
//In View
<form action="@Url.Action("UploadPayment")" method="post" enctype="multipart/form-data">
<input type="file" name="FileUploads" id="FileUploads1" />
<input type="file" name="FileUploads" id="FileUploads2" />
//In Model
public IEnumerable<HttpPostedFileBase> FileUploads { get; set; }
@sphingu
sphingu / MVC_InterView_Questions.md
Created June 19, 2013 09:18
MVC Interview Questions

Interview Question


1.In which assembly is the MVC framework defined? System.Web.Mvc

2.What is ViewData, ViewBag and TempData?

  MVC offers Three options for passing data from controller to View and  in next request. 
ViewData & ViewBag are almost similar.
  	Short life means value becomes null when redirection occurs.
		It’s a communication mechanism within the server call.
Difference between ViewBag & ViewData:
Install-Package EntityFramework
Update-Database -Verbose -Force
Enable-Migrations -EnableAutomaticMigrations -Force
Add-Migration //not compulsory
int
string
DateTime
byte[] for binary image
Guid