Skip to content

File Upload MVC Razor







<h2>Upload File</h2>

<form method="post" enctype="multipart/form-data">

<label>Filename: <input type="file" name="file" /></label>

<input type="submit" value="Submit" />





After adding a control in view adds the following code in the controller to upload the file on the server:

using System.Web.Mvc;

using System.IO;

using System.Web;

namespace FileUploadDemo.Controllers


public class HomeController : Controller


public ActionResult Index()


return View();



public ActionResult Index(HttpPostedFileBase file)


var fileName = Path.GetFileName(file.FileName);

if (fileName != null)

file.SaveAs(Server.MapPath("~\\files\\" + fileName));

return View();





Visual Studio to Debug JavaScript in IE

Code First with Entity Framework 5 using MVC4 and MVC Scaffold

TSQL Paging schnell


SET @PageSize = 10;
SET @PageNum = 1;

WITH Products AS
    SELECT *, ROW_NUMBER() OVER(ORDER BY lngProductID) AS RowNum     
      FROM tblProduct

  FROM Products
WHERE RowNum BETWEEN (@PageNum – 1) * @PageSize + 1
                  AND @PageNum * @PageSize
ORDER BY lngProductID;

Paging Langsam 2 sec.

— Set the page bounds
    DECLARE @PageLowerBound int
    DECLARE @PageUpperBound int
    DECLARE @TotalRecords   int
    DECLARE @PageSize   int
    DECLARE @PageIndex   int
    SET @PageSize = 10
    SET @PageIndex = 0
    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageSize – 1 + @PageLowerBound

    — Create a temp table TO store the select results
    CREATE TABLE #PageIndexForProducts
        IndexId int IDENTITY (0, 1) NOT NULL,
        ProductId int
     INSERT INTO #PageIndexForProducts (ProductID)
            SELECT p.lngProductID
            FROM   tblProduct p
            ORDER BY p.lngProductID
select * from tblProduct p inner join #PageIndexForProducts i
    on p.lngProductID = i.ProductId   
    where i.IndexId >= @PageLowerBound and i.IndexId <= @PageUpperBound            
–SELECT  @TotalRecords = COUNT(*)
–    FROM    #PageIndexForProducts
–    RETURN @TotalRecords
Drop TABLE #PageIndexForProducts