A
Ankush Jassal
Guest
I am inserting audio in database using entity framework. Heres a description:-
In upload page user can upload their song by selecting type like Hindi, Punjabi, Old and English. If user select Punjabi then that audio and data will save into Punjabi database that i create in sql server 2008 and it will also save in folder under "Media/Punjabi". The problem is its not inserting into database. It not showing any error or run-time exception. Can anyone please help.
Heres a code:-
Model Class:-
public class Upload_song
{
[Required(ErrorMessage = "Please enter singer name")]
[DisplayName("Enter singer name")]
public string Name { get; set; }
[Required(ErrorMessage = "Please enter email id")]
[DataType(DataType.EmailAddress)]
[DisplayName("Enter your emailid")]
public string Email { get; set; }
[Required(ErrorMessage = "Please enter your country")]
[DisplayName("Enter your Country")]
public string Country { get; set; }
[Required(ErrorMessage = "Please enter your state")]
[DisplayName("Enter your State")]
public string State { get; set; }
[Required(ErrorMessage = "Please enter your city")]
[DisplayName("Enter your City")]
public string City { get; set; }
[Required(ErrorMessage = "Please enter your song")]
[DisplayName("Enter your Song")]
public HttpPostedFileBase Song { get; set; }
[Required(ErrorMessage = "Please enter the type")]
[DisplayName("Enter type of song")]
public string Song_type { get; set; }
}
HomeController.cs
public ActionResult Upload(Upload_song us)
{
return View();
}[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
Upload_song us=new Upload_song();
if (us.Song_type == "Punjabi")
{
if (file.ContentLength > 0)
{
var filename = Path.GetFileName(file.FileName);
var audiopath = Path.Combine(Server.MapPath("~/Media/Punjabi"), filename);
file.SaveAs(audiopath);
ae.AddToPunjabis(us);
ae.SaveChanges();
}
ViewBag.Message = "Upload successfully";
}
return View();
}
Upload.csHtml
@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype="multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Upload Song</legend>
<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" id="file" />
</div>
<div class="editor-label">
<select name="song type" class="upload_text">
<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" style="font-size:medium" />
</p>
Can anyone help me regarding this question.
Continue reading...
In upload page user can upload their song by selecting type like Hindi, Punjabi, Old and English. If user select Punjabi then that audio and data will save into Punjabi database that i create in sql server 2008 and it will also save in folder under "Media/Punjabi". The problem is its not inserting into database. It not showing any error or run-time exception. Can anyone please help.
Heres a code:-
Model Class:-
public class Upload_song
{
[Required(ErrorMessage = "Please enter singer name")]
[DisplayName("Enter singer name")]
public string Name { get; set; }
[Required(ErrorMessage = "Please enter email id")]
[DataType(DataType.EmailAddress)]
[DisplayName("Enter your emailid")]
public string Email { get; set; }
[Required(ErrorMessage = "Please enter your country")]
[DisplayName("Enter your Country")]
public string Country { get; set; }
[Required(ErrorMessage = "Please enter your state")]
[DisplayName("Enter your State")]
public string State { get; set; }
[Required(ErrorMessage = "Please enter your city")]
[DisplayName("Enter your City")]
public string City { get; set; }
[Required(ErrorMessage = "Please enter your song")]
[DisplayName("Enter your Song")]
public HttpPostedFileBase Song { get; set; }
[Required(ErrorMessage = "Please enter the type")]
[DisplayName("Enter type of song")]
public string Song_type { get; set; }
}
HomeController.cs
public ActionResult Upload(Upload_song us)
{
return View();
}[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
Upload_song us=new Upload_song();
if (us.Song_type == "Punjabi")
{
if (file.ContentLength > 0)
{
var filename = Path.GetFileName(file.FileName);
var audiopath = Path.Combine(Server.MapPath("~/Media/Punjabi"), filename);
file.SaveAs(audiopath);
ae.AddToPunjabis(us);
ae.SaveChanges();
}
ViewBag.Message = "Upload successfully";
}
return View();
}
Upload.csHtml
@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype="multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Upload Song</legend>
<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" id="file" />
</div>
<div class="editor-label">
<select name="song type" class="upload_text">
<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" style="font-size:medium" />
</p>
Can anyone help me regarding this question.
Continue reading...