Showing posts with label MVC2. Show all posts
Showing posts with label MVC2. Show all posts

Friday, November 12, 2010

FileUploader in asp.net MVC2

as we all know ASP.NET MVC sits on top of ASP.NET. That means ASP.NET MVC didn't do any special work for File Upload support. It uses whatever stuff is built into ASP.NET itself.

So the core process is still same for file upload:
below is code for view

Code for how to Upload file in ASP.NET MVC2



< %@ Page Title="" Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage" % >

< asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server" >
FileUpload
< /asp:Content >
< asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >
< h2 >FileUpload< /h2 >

< % using (Html.BeginForm("FileUpload", "FileUpload",
FormMethod.Post, new { enctype = "multipart/form-data" }))
{% >
< input name="uploadFile" type="file" / >
< input type="submit" value="Upload File" / >
< %} % >

< /asp:Content >


//and this is code for controller class:
[HandleError]
public class FileUploadController : Controller
{
public ActionResult FileUpload()
{
return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"),
Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
}

How to Upload file in ASP.NET MVC2 by Rajesh Rolen

Read More

Sunday, October 31, 2010

How to add attributes with controls in MVC2

this is how we can add attributes with HTML controls in MVC2 :


< %: Html.TextBox("txtfind", null, new { @maxlength = "5", @class = "findInput" })% >


in above sample we are setting max length property of textbox to 5 and adding its css class name "findinput".

Solutions By:Rajesh Rolen

Read More

Tuesday, October 26, 2010

Partial Update in MVC2 (like update panel in classic asp.net)

     
function showAjaxMessage(targetDiv, ajaxMessage) {
var ajaxLoader = "";
$(targetDiv).html("

" + ajaxLoader + " " + ajaxMessage + "

");
}
function submitme() {
submitForm("MyFunction", "#dvdamageAreaMid", "Submitting...", "#BodyWork", function () { alert('Submitted!'); });
}
function submitToPartialView(data) {
getPartialView("UCDamage", "#dvdamageAreaMid", "Loading...", function () { },data );
}

function getPartialView(actionUrl, targetDiv, ajaxMessage, callback,data) {
showAjaxMessage(targetDiv, ajaxMessage);

$.get(actionUrl, { searchText: data }, function (result) {
$(targetDiv).html(result);
callback();
});
}
function submitForm(actionUrl, targetDiv, ajaxMessage, form, callback) {

var data = $(form).serialize();
showAjaxMessage(targetDiv, ajaxMessage);
$.post(
actionUrl,
data,
function (data) {
$(targetDiv).html(data);
callback();
}
);
}
Read More
Powered By Blogger · Designed By Seo Blogger Templates