I'm not sure if this is an issue my grid configuration or just a general MVC issue I am having but I've got a grid in a partial view and when I try to delete an item it is posting to the parent view controller method instead of the method I have configured in the grid. I believe I have the views configured correctly but I must be missing something.
View:
The partial view is called by the @Html.Action
Partial View:
Controller Methods:
When I try to debug, the DeleteFindingSource Post method is not reached but instead the Required Post method (which is the parent view) is called.
Thanks.
View:
@model PASS.ViewModels.Proposals.RequiredViewModel
@using (Ajax.BeginForm("Required", "Proposals", new AjaxOptions { UpdateTargetId = "requiredReturnMsg", HttpMethod = "Post" }))
{
@Html.HiddenFor(model => model.Proposal_ID, Model.Proposal_ID)
<
div
class
=
"editor-container"
>
<
div
class
=
"editor-label"
>
@Html.Label("Funding Source")
</
div
>
<
div
class
=
"editor-field"
>
@Html.DropDownListFor(model => model.Funding_Source_ID, new SelectList(Model.FundingSources, "Value", "Text"), "(Select One)")
@Html.ValidationMessageFor(model => model.Funding_Source_ID)
</
div
>
<
br
class
=
"clear"
/>
<
div
class
=
"editor-label"
>
@Html.Label("Specify (only if requested)")
</
div
>
<
div
class
=
"editor-field"
>
@Html.TextBoxFor(model => model.Funding_Specify, new { style = "width: 350px;" })
@Html.ValidationMessageFor(model => model.Funding_Specify)
</
div
>
<
br
class
=
"clear"
/>
<
br
/>
<
br
/>
<
p
><
input
type
=
"submit"
value
=
"Add Funding Source"
/></
p
>
<
br
/>
<
br
/>
@Html.Action("FundingSources", "Proposals", new { proposalID = Model.Proposal_ID })
<
br
/>
<
br
/>
<
div
id
=
"requiredReturnMsg"
></
div
>
</
div
>
}
Partial View:
@model IEnumerable<
PASS.ViewModels.Proposals.FundingSourcesViewModel
>
@using (Ajax.BeginForm("FundingSources", "Proposals", new AjaxOptions { }))
{
<
div
style
=
"width:95%;"
>
@(Html.Kendo().Grid(Model)
.Name("gvFundingSources")
.Columns(columns =>
{
columns.Bound(o => o.FundingSourceDescription).Title("Funding Source");
columns.Bound(o => o.Funding_Specify).Title("Specifics");
columns.Command(command => { command.Destroy(); }).Width(50);
})
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(o => o.ID))
.Read(read => read.Action("FundingSources", "Proposals"))
.Destroy(destroy => destroy.Action("DeleteFundingSource", "Proposals"))
)
)
</
div
>
}
Controller Methods:
public ActionResult Required(int proposalID)
{
var context = new PASSEntities();
RequiredViewModel model = new RequiredViewModel
{
Proposal_ID = proposalID,
FundingSources = context.Funding_Sources.ToList().Select(m => new SelectListItem { Value = m.ID.ToString(), Text = m.Description }).ToList()
};
return PartialView(model);
}
[HttpPost]
public ActionResult Required(RequiredViewModel model)
{
try
{
var context = new PASSEntities();
var fundingsource = context.Proposal_Funding_Sources.Find(model.ID);
bool bAdd = false;
if (fundingsource == null) {
fundingsource = new Proposal_Funding_Sources();
bAdd = true;
}
fundingsource.Funding_Source_ID = model.Funding_Source_ID;
fundingsource.Proposal_ID = model.Proposal_ID;
fundingsource.Funding_Specify = model.Funding_Specify;
if (bAdd) context.Proposal_Funding_Sources.Add(fundingsource);
else context.Entry(fundingsource).State = System.Data.EntityState.Modified;
context.SaveChanges();
var message = new SystemMessage(Models.eMessageType.SUCCESS);
message.Message = "Your data has been saved!";
return PartialView("_SystemMessage", message);
}
catch
{
var message = new SystemMessage(Models.eMessageType.ERROR);
message.Message = "Save Failed!";
return PartialView("_SystemMessage", message);
}
}
[ChildActionOnly]
public ActionResult FundingSources(int proposalID)
{
var context = new PASSEntities();
var model = (from a in context.Proposal_Funding_Sources
join b in context.Funding_Sources on a.Funding_Source_ID equals b.ID
where a.Proposal_ID == proposalID
select new FundingSourcesViewModel()
{
ID = a.ID,
Proposal_ID = a.Proposal_ID,
Funding_Source_ID = a.Funding_Source_ID,
Funding_Specify = a.Funding_Specify,
FundingSourceDescription = b.Description
});
return PartialView(model);
}
[HttpPost]
[ChildActionOnly]
public ActionResult DeleteFundingSource(int id)
{
try
{
using (PASSEntities context = new PASSEntities())
{
var fundingsource = context.Proposal_Funding_Sources.Find(id);
context.Entry(fundingsource).State = System.Data.EntityState.Deleted;
context.SaveChanges();
}
var message = new SystemMessage(Models.eMessageType.SUCCESS);
message.Message = "Your data has been saved!";
return PartialView("_SystemMessage", message);
}
catch
{
var message = new SystemMessage(Models.eMessageType.ERROR);
message.Message = "Save Failed!";
return PartialView("_SystemMessage", message);
}
}
When I try to debug, the DeleteFindingSource Post method is not reached but instead the Required Post method (which is the parent view) is called.
Thanks.