Helo
Iam designed an form in view page which looks like
<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" />
}
</div>
<script type="text/javascript">
$(function () {
$('.photoupload').click(function (event) {
$('#userid').val(event.target.id);
$('#dialog').dialog('open');
});
$('#photouploadform').submit(function () {
$.getJSON("/Image/Upload/", {
userid: $('#Id').val(),
file1: $('#fileUpload')
},
function(success){
alert(str.st)
},
function (data) {
$('#dialog').append('<p>' + data + '</p>');
});
return false;
});
$("#dialog").dialog({
autoOpen: false,
show: "blind",
width: 400,
hide: "fade",
modal: true,
resizable: false
});
});
</script>
In my controller i give like
public ActionResult Upload(int userid,HttpPostedFileBase file1)
{
Image g = new Image();
g.Userid = userid;
if (file1 != null)
{
g.Image1 = file1;
}
try
{
this.dbContext.Add(g);
this.dbContext.SaveChanges();
}
catch
{
}
var str = new { st = "Successfully Saved" };
return Json(str, JsonRequestBehavior.AllowGet);
}
when i click upload it is showing server 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.
Can any one knows please tell me the solution