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 :-
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Upload.csHtml:-
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
@Html.LabelFor(model => model.Email)
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
@Html.LabelFor(model => model.Country)
@Html.EditorFor(model => model.Country)
@Html.ValidationMessageFor(model => model.Country)
@Html.LabelFor(model => model.State)
@Html.EditorFor(model => model.State)
@Html.ValidationMessageFor(model => model.State)
@Html.LabelFor(model => model.City)
@Html.EditorFor(model => model.City)
@Html.ValidationMessageFor(model => model.City)
@Html.LabelFor(model => model.Song)
}
In Controller.cs:-
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.
Ankush JassalPosted Apr 10, 2015, 1:05 AM
Ankush JassalPosted Mar 30, 2015, 11:38 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace MvcApplication20.Models
{
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")] //This is an URL of that audio that i want to save.
[DisplayName("Enter your Song")]
public string Song { get; set; }
[Required(ErrorMessage = "Please enter the type")]
[DisplayName("Enter type of song")]
public string Song_type { get; set; }
}
}
Pradeep ShetPosted Mar 29, 2015, 11:18 AM
Will it be possible to show the model class . Does it has a parameterized constructor defined?