没有为此对象定义参数少构造函数 [英] No Parameter Less Constructor defined for this Object
本文介绍了没有为此对象定义参数少构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
自过去2天以来,我收到此错误.无法摆脱它.
我有一个简单的数据输入表单,您可以在其中添加客户端名称及其信息.有2个下拉菜单国家和州.在选择国家时,填入州草稿.但是,当我单击保存"按钮时,出现错误为此对象定义了无参数的构造函数"
这是我的代码
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; }
//[Required(ErrorMessage = "Kindly select Country")]
public string CountryName{ get; set; }
public int StateID { get; set; }
//[Required(ErrorMessage = "Kindly Select State")]
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" })%>
<%--new { onchange = "this.form.action='/ClientMasterNew/CreateClient';this.form.submit();" }--%>
<%--<%: Html.ValidationMessageFor(model => model.clsClientMaster.CountryName)%>--%>
</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" })%>
<%-- <%: Html.ValidationMessageFor(model => model.clsClientMaster.client_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));
//Fill_Countries(false, 0, Convert.ToInt32(id));
return Json(StateList, JsonRequestBehavior.AllowGet);
}
public IList<StateMaster> GetStates(int cid)
{
//to fill state dropdown
IList<StateMaster> States = BAL_ClientMaster.Fill_States(cid).ToList();
return States;
}
//[AcceptVerbs(HttpVerbs.Get)]
//public ActionResult CreateClient(ClientMaster_ViewModel cmVM)
//{
// int countryID = Convert.ToInt32(cmVM.selectedCountry);
// Fill_Countries(ref cmVM, true, 0, countryID);
// return View(cmVM);
//}
//
// POST: /ClientMasterNew/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(FormCollection collection, ClientMaster_ViewModel cmVM)
{
try
{
int CountryId = 0, stateid = 0;
// TODO: Add insert logic here
if (ModelState.IsValid)
{
CountryId = Convert.ToInt32(collection["ClientMaster_ViewModel.Country"]);
stateid = Convert.ToInt32(collection["ClientMaster_ViewModel.State"]);
//var name = model.client_Name;
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();
}
//return View();
}
推荐答案
(文档).ready(功能(){
(document).ready(function () {
(" ).change(功能(){ var c_id =
("#Country").change(function () { var c_id =
( this ).val();
这篇关于没有为此对象定义参数少构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文