Hello friends,
i m getting this error since past 2 days. cant get out of it.
i have simple data entry form where u add the name of the client and its information. there are 2 dropdown country and state. on selecting country, state drodpdown is filled. But when i click the save button i get the Error "No Parameter Less constructor Defined for this object"
Here is my code
<pre lang="c#">public class ClientMaster
{
public int client_ID { get; set; }
[Required (ErrorMessage="Enter Client Name")]
public string client_Name { get; set; }
[Required (ErrorMessage="Enter Client Address")]
public string client_Address { get; set; }
public string client_Address1 { get; set; }
public string client_Address2 { get; set; }
[Required(ErrorMessage = "Enter Client Phone Number")]
public long client_Phone { get; set; }
public long client_Fax { get; set; }
public long client_Mobile { get; set; }
public int CountryID { get; set; }
public string CountryName{ get; set; }
public int StateID { get; set; }
public string StateName { get; set; }
[Required(ErrorMessage = "Enter the Client City")]
public string client_City { get; set; }
[Required(ErrorMessage = "Enter the Client Zip Code")]
public int client_Zip { get; set; }
public string last_Updated_By { get; set; }
public string updated_Date { get; set; }
public DateTime record_lock_timestamp { get; set; }
public bool client_status { get; set; }
}
<pre lang="c#">public class ClientMaster_ViewModel
{
public ClientMaster clsClientMaster { get; set; }
public SelectList Country { get; set; }
public SelectList State { get; set; }
[Required(ErrorMessage="Kindly Select Country")]
public int selectedCountry { get; set; }
}
<script type="text/javascript">
$(document).ready(function () {
$("#Country").change(function () {
var c_id = $(this).val();
$.getJSON("/ClientMasterNew/GetState", { id : c_id }, function (myData) {
var select = $("#State");
select.empty();
$.each(myData, function (index, itemData) {
select.append($('<option/>', {
value : itemData.ID,
text : itemData.StateName
}))
});
});
});
});
</script>
<% using (Html.BeginForm("Create", "ClientMasterNew", FormMethod.Post,this.Model))
{ %>
<%: Html.ValidationSummary(true, "New Client Creation was unsuccessful. Please correct the errors and try again.")%>
<fieldset>
<legend>ClientMaster</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Name)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Name)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Name)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Address)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Address)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Address)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Address1)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Address1)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Address1)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Address2)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Address2)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Address2)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Phone)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Phone)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Phone)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Fax)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Fax)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Fax)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Mobile)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Mobile)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Mobile)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.CountryName)%>
</div>
<div class="editor-field">
<%: Html.DropDownListFor(model => model.selectedCountry,(SelectList)ViewData["Countries"], new { id = "Country" })%>
<%----%>
<%----%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.StateName)%>
</div>
<div class="editor-field">
<%: Html.DropDownListFor(model => model.State, (SelectList)ViewData["States"], new { id = "State" })%>
<%----%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_City)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_City)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_City)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_Zip)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_Zip)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_Zip)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.clsClientMaster.client_status)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.clsClientMaster.client_status)%>
<%: Html.ValidationMessageFor(model => model.clsClientMaster.client_status)%>
</div>
<p>
<input type="submit" value="Create" />
</p>
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetState(string id)
{
var StateList = GetStates(Convert.ToInt32(id));
return Json(StateList, JsonRequestBehavior.AllowGet);
}
public IList<StateMaster> GetStates(int cid)
{
IList<StateMaster> States = BAL_ClientMaster.Fill_States(cid).ToList();
return States;
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(FormCollection collection, ClientMaster_ViewModel cmVM)
{
try
{
int CountryId = 0, stateid = 0;
if (ModelState.IsValid)
{
CountryId = Convert.ToInt32(collection["ClientMaster_ViewModel.Country"]);
stateid = Convert.ToInt32(collection["ClientMaster_ViewModel.State"]);
string[] arr_val = BAL_ClientMaster.InsertClient(cmVM, CountryId, 1, "Ketan Naik");
if (Convert.ToBoolean(arr_val[0]) == true)
{
ViewData["OutPutMsg"] = Convert.ToString(arr_val[1]);
return RedirectToAction("Index", "ClientMasterNew");
}
else
{
ModelState.AddModelError("", Convert.ToString(arr_val[1]));
}
}
Fill_Countries(ref cmVM, true, CountryId, stateid);
return View(cmVM);
}
catch
{
return View();
}
}