I can not save some data, probably the error is in the parameters.
My Controller:
public ActionResult SalvarMilestone(Milestone milestone, int CodigoProjeto)
{
//if (ModelState.IsValid)
//{
try
{
using (CPMDatabaseEntities dc = new CPMDatabaseEntities())
{
milestone.CodigoProjeto = CodigoProjeto;
dc.Milestone.Add(milestone);
dc.SaveChanges();
}
}
catch (Exception)
{
throw;
}
//}
return View(milestone);
}
My SCRIPT that returns the data:
<script>
$(document).ready(function () {
$("#AjaxPost").click(function () {
var dataObject = {
Descricao: $("#Descricao").val(),
codigoProjeto: $("#CodigoProjeto").val(),
TipoCalculo: $('#TipoCalculo :selected').text(),
};
$.ajax({
url: "@Url.Action("SalvarMilestone", "Dashboard")",
type: "POST",
data: dataObject,
dataType: "json"
});
});
});
Mod SCRIPT:
$(".AddMarco").click(function () {
var CodigoProjeto = $(this).attr("data-id");
$("#modal").load("AddMilestone?CodigoProjeto=" + CodigoProjeto, function () {
$(".modal").modal();
})
});
I get the value of the project code with this button
<input id="AjaxPost" value="Salvar" data-id="@ViewBag.CodigoProjeto" class="btn btn-primary" data-dismiss="modal" />
The parameters dictionary contains a null entry for parameter 'CodigoProjeto' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult SalvarMilestone(ISystemCritical.Models.Milestone, Int32)' in 'ISystemCritical.Controllers.DashboardController'.
An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Nome do parâmetro: parameters
Probably the error is in the parameter passing, because when I access the Dashboard / SaveMilestone link? ProjectCode = 1 it runs my controller.