How to save image into database using linq query

Posted by Prasanna64 under ASP.NET on 5/21/2012 | Points: 10 | Views : 2232 | Status : [Member] | Replies : 0

I designed the upload control when i click save button it is to be saved to the database and display it from the database.My table columns are Id,userid,image1

My view page is
<a href="#" class="photoupload" id="Id1">Upload File</a>

<div id="dialog" title="Upload files">
@using(Html.BeginForm("Upload","Image", FormMethod.Post, new {id="photouploadform", enctype = "multipart/form-data" }))
<p><input type="file" id="fileUpload" name="fileUpload" size="23"/> </p><br />
<p><input type="submit" value="Upload file" /></p>
<input type="hidden" id="Id" value="1" />

<script type="text/javascript">
$(function () {
$('.photoupload').click(function (event) {

$('#photouploadform').submit(function () {
$.getJSON("/Image/Upload/", {
userid: $('#Id').val(),
file1: $('#fileUpload')
function (data) {
$('#dialog').append('<p>' + data + '</p>');
return false;

autoOpen: false,
show: "blind",
width: 400,
hide: "fade",
modal: true,
resizable: false



my controller file looks like

public ActionResult Upload(int userid,HttpPostedFileBase file1)

Image g = new Image();
g.Userid = userid;

if (file1 != null)
g.Image1 = file1;



var str = new { st = "Successfully Saved" };

return Json(str, JsonRequestBehavior.AllowGet);

when i click upload am getting this error can any one help me to solve this error

The parameters dictionary contains a null entry for parameter 'Id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Upload(Int32, System.Web.HttpPostedFileBase)' in 'Dataview.Controllers.ImageController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters


(No response found.)

Login to post response