I'm new to "ASP.NET MVC 2" and "C #". I researched a lot, but really could not find anything that solves my problem so far. I'm having trouble receiving a multiselect field on the server side. I have a html form that has 5 select fields that can be optionally used by the user. 3 of 5 fields have the "Multiple" property. Here is the form:
//file "formHtml1.ascx"
<div>
<select name="app" id="app">
<option value="">All</option>
<% foreach (My.Namespace.App app in Model.App) { %>
<option value="<%:app.Id %>"><%:app.Name %></option>
<% } %>
</select>
</div><div>
<select name="etp" id="etp">
<option value="">All</option>
<option value="1">EF</option>
<option value="2">EM</option>
</select>
</div><div>
<select name="esc[]" id="esc" multiple="multiple">
<% foreach (My.Namespace.Esc esc in Model.Esc) { %>
<option value="<%:esc.Id %>"><%:esc.Name %></option>
<% } %>
</select>
</div><div>
<select name="ans[]" id="ans" multiple="multiple">
<% foreach (My.Namespace.Ans ans in Model.Ans) { %>
<option value="<%:ans.Id %>"><%:ans.Name %></option>
<% } %>
</select>
</div><div>
<select name="ar[]" id="ar" multiple="multiple">
<% foreach (My.Namespace.Ar ar in Model.Ars) { %>
<option value="<%: ar.Id %>"><%: ar.Name %></option>
<% } %>
</select>
</div>
</div>
My Controller receives the Form through a Model (at least, that was what it should do, i guess)
// file MyController.cs
[HttpPost]
public PartialViewResult MyAction(MyModel model)
{
try
{
MyClassBO bo = new MyClassBO();
MyDependency myDependency = bo.GerRelEqpHab(model.TpRel, model.AgpQA, model.AgpQE, model.FilterApp, model.FilterEtp, model.FilterEsc, model.FilterAns, model.FilterAr);
DataTable dataTable = myDependency.Table;
string nameRel = myDependency.NameRel;
model.NameRel = nameRel;
model.Registers = dataTable;
ViewData.Model = model;
return PartialView("Partials/GerRel");
}
catch (Exception e)
{
throw e;
}
}
And here is the model that's being used:
// file "MyModel.cs"
public class MyModel
{
public DataTable Registers { get; set; }
public string TpRel { get; set; }
public string AgpQA { get; set; }
public string AgpQE { get; set; }
public int? FilterApp { get; set; }
public int? FilterEtp { get; set; }
public int?[] FilterEsc { get; set; }
public int?[] FilterAns { get; set; }
public int?[] FilterAr { get; set; }
public bool Printing { get; set; }
public bool DownloadXLS { get; set; }
public string NameRel { get; set; }
public Dictionary<string, string> Filters { get; set; }
public MyModel(string tipoRelatorio, string agrupamentoQtdAlunos, string agrupamentoQtdEscolas, int? filtroAplicacao, int? filtroEtapa, int?[] filtroEscola, int?[] filtroSerie, int?[] filtroArea, bool printing, bool downloadXLS)
{
this.TpRel = tipoRelatorio;
this.AgpQA = agrupamentoQtdAlunos;
this.AgpQE = agrupamentoQtdEscolas;
this.FilterApp = filtroAplicacao;
this.FilterEtp = filtroEtapa;
this.FilterEsc = filtroEscola;
this.FilterAns = filtroSerie;
this.FilterAr = filtroArea;
this.Printing = printing;
this.DownloadXLS = downloadXLS;
}
public MyModel(string tipoRelatorio, string agrupamentoQtdAlunos, string agrupamentoQtdEscolas, int? filtroAplicacao, int? filtroEtapa, int?[] filtroEscola, int?[] filtroSerie, int?[] filtroArea)
{
this.TpRel = tipoRelatorio;
this.AgpQA = agrupamentoQtdAlunos;
this.AgpQE = agrupamentoQtdEscolas;
this.FilterApp = filtroAplicacao;
this.FilterEtp = filtroEtapa;
this.FilterEsc = filtroEscola;
this.FilterAns = filtroSerie;
this.FilterAr = filtroArea;
}
}
When I compile the code, everything runs fine. But when I run the project, I get the following 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.
And I can't figure out what is wrong.