Click here to Skip to main content
13,289,653 members (58,330 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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" />
<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

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;
           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
Posted 20-May-12 21:25pm
Updated 25-May-12 6:21am
ryanb31 25-May-12 11:21am
fixed code tags
ryanb31 25-May-12 11:22am
It isn't clear to me by looking at the code but there appears to be an issue of ID not being passed into the database procedure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100