Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am beginner for mvc 4, and working on a project in mvc 4 by using visual studio 2012 and I have created a form that user fill it. at the last raw of the form there is a buton use to upload image. I have created Donate Module, Donate view, Donate Controller. But I coudnt create a code in controller that help to accept the data fill by user and image uploaded and save it to the local database which I have created. any one can help me the code that use to save the data with image in database? thank you for your help.

THE FORM HAS THE FOLLOWING ROWS:
The form will look like this.
UserName.
ItemType
ItemDescription
Date
UploadImage


// In Module,

C#
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace BootstrapPager.Models
{
    public class Donate
    {
        [Required]
        public int Id { get; set; }
        [Required]
        [Display(Name = "UserName")]
        public string UserName { get; set; }

        [Required]
        [Display(Name = "ItemType")]
        public string ItemType { get; set; }

         [Required]
        [Display(Name = "ItemDescription")]
        public string ItemDescription { get; set; }
         [Required]
         [Display(Name = "Date")]
         public string Day { get; set; }
        }
    
         [Required]
         [Display(Name = "UploadImage")]
         public string UploadImage { get; set; }

    }
// my view

div class="col-xs-12">
    <div class="row">
        <div class="col-sm-8">
            <div class="page-header">
                <h2> Donate </h2>
            </div>
            @using (Html.BeginForm())
            {
                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)
            

                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            @Html.LabelFor(model => model.UserName, "UserName", new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.UserName, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.UserName, null,new { @class = "text-danger" })
                        </div>
                    </div>
                     </div>
                  <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            @Html.LabelFor(model => model.ItemType, "ItemType", new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.ItemType, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.ItemType, null,new { @class = "text-danger" })

                        </div>
                    </div>
                </div>

              <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            @Html.LabelFor(model => model.ItemDescription, "ItemDescription", new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.ItemDescription, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.ItemDescription, null,new { @class = "text-danger" })

                        </div>
                    </div>
                  </div>
                   <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            @Html.LabelFor(model => model.Day, "Day", new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.Day, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.Day, null,new { @class = "text-danger" })

                        </div>
            
                        </div>
                     <div class="col-md-6">
                        <div class="form-group">
                            @Html.LabelFor(model => model.Year, "Year", new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.Year, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.Year, null,new { @class = "text-danger" })

                        </div>
                    </div>
                       </div>
                 <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            @Html.LabelFor(model => model.UploadImage, "UploadImage", new { @class = "control-label" })
                            @Html.TextBoxFor(model => model.UploadImage, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.UploadImage, null,new { @class = "text-danger" })

                        </div>
                    </div>

                </div>
             <div class="form-group text-center">
                    <button type="submit" class="btn btn-success btn-lg">Submit</button>
                </div> 
             }</div></div>
Posted
Updated 29-May-14 8:12am
v6
Comments
CHill60 29-May-14 6:47am    
You need to use the Improve question link to format your question and remove the link
[no name] 29-May-14 12:41pm    
There is no code that attempts to save any data to a database in your update.
Member 10651775 29-May-14 12:52pm    
I mean the code which I have to write in controller
[no name] 29-May-14 13:18pm    
How would you expect us to know based on what you have here? Go read the documentation for whatever database engine that you are using. Do some research. Write some code.
Member 10651775 29-May-14 13:23pm    
Thank you for your comment

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900