In MVC4, how do I upload a file (an image) to MSSQL that's part of my domain model?

JokeAss

New Member
I'm relatively new to MVC, and I've never had to deal with uploading a file (an image, specifically) to an MSSQL database. To be honest, I don't know what I'm doing here. Here's what I have so far- Here's my domain model (note the HttpPostedFileBase in my model- this is what I want to upload):\[code\]public class Profile{ [Key] public int Id { get; set; } [Required(ErrorMessage="Years of service is required")] [DisplayName("Years Service:")] public int YearsService { get; set; } [DataType(DataType.MultilineText)] [DisplayName("Notable Achivements:")] public string NotableAchivements { get; set; } [Required(ErrorMessage = "Technical skills are required")] [DataType(DataType.MultilineText)] [DisplayName("Technical Skills:")] public string TechnicalSkills { get; set; } [DisplayName("Upload Image: ")] public HttpPostedFileBase Photo { get; set; } public string CreatedBy { get; set; } public DateTime CreatedDate { get; set; } public string ModifiedBy { get; set; } public DateTime ModifiedDate { get; set; }}\[/code\]And here's my view:\[code\]@using (Html.BeginForm("Create", "Profiles", FormMethod.Post, new { enctype = "multipart/form-data" })){<div class="editor-label"> @Html.LabelFor(model => model.YearsService)</div><div class="editor-field"> @Html.EditorFor(model => model.YearsService) @Html.ValidationMessageFor(model => model.YearsService)</div><div class="editor-label"> @Html.LabelFor(model => model.NotableAchivements)</div><div class="editor-field"> @Html.EditorFor(model => model.NotableAchivements) @Html.ValidationMessageFor(model => model.NotableAchivements)</div><div class="editor-label"> @Html.LabelFor(model => model.TechnicalSkills)</div><div class="editor-field"> @Html.EditorFor(model => model.TechnicalSkills) @Html.ValidationMessageFor(model => model.TechnicalSkills)</div><input type="file" name="photo" /><input type="submit" name="Submit" id="Submit" value="http://stackoverflow.com/questions/15484483/Upload" />}\[/code\]I hope there's something glaringly obvious that I'm doing wrong. Can anyone provide advice on how to do a simple file upload to an MSSQL database?
 
Back
Top