I am saving audio and other data in database using asp.net mvc 3 and entity framework but the problem i got is an run-time exception :-
<div class="upload">
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Upload your song</legend>
<div class="upload_text">
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Country)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Country)
@Html.ValidationMessageFor(model => model.Country)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.State)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.State)
@Html.ValidationMessageFor(model => model.State)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.City)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.City)
@Html.ValidationMessageFor(model => model.City)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Song)
</div>
<div class="editor-field">
<input type="file" name="song" />
</div>
<div class="editor-label">
<select name="song type">
<option>-Select song type-</option>
<option>Old is Gold</option>
<option>Hindi songs</option>
<option>Punjabi songs</option>
<option>English songs</option>
</select>
</div>
<p>
<input type="submit" value="Create" />
</p>
</div>
</fieldset>
}
</div>
public ActionResult Upload(Upload_Song upload)
{
return View();
}
[HttpPost]
public ActionResult Upload(HttpPostedFile file)
{
Upload_Song upload = new Upload_Song();
ae.AddToUpload_Song(upload);
ae.SaveChanges();
if(upload.Song_type=="Punjabi")
{
if(file.ContentLength>0)
{
var filename=Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Media/Punjabi"),filename);
file.SaveAs(path);
}
ViewBag.Message = "Upload successfully";
return RedirectToAction("Index");
}
return View();
}
Can anyone please help where i am wrong.