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,
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; }
}
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>