I have a form where user can create a complex object. When click on "Add action", then an Ajax call is made in JS, and I use a partialview as return, then I show it as accordion in the form and all is OK for that creation form.
Now, I want to make the same form but for editing, so I have my basic form that works well, but I'm like blocked for the edit form, especially for the partiaviews called by pressing the "Add action" button ...
In the Edit Form, I have a List that contains all the data of each "add action", How can I handle/load/show this in the view?
Can I make one include of the partialView (and passing data) by only using C#?
here is what I've did:
Finally, this is my ajax call from Create JS:
var x = 0; // problem count
// method called when user click on add problem
$(".add_action_button").click(function (event) {
event.preventDefault();
// ajax call to partial with prefix
var prefix = "actionList[" + x + "]";
$.ajax({
url: "@Url.Action("AddAction", "Home")",
cache: false,
type: "GET",
dataType: "html",
traditional: true,
data: { prefix: prefix, accordioncounter: x + 1 },
success: function (result) {
// lot of stuff
}
});
});
AddAction Controller:
public ActionResult AddAction(string prefix, int accordioncounter)
{
ViewBag.Prefix = prefix;
ViewBag.accordioncounter = accordioncounter;
return PartialView("_AddAction", new ActionViewModel());
}
_AddAction View:
@model MyModel.ActionViewModel
@{
if (!string.IsNullOrEmpty(ViewBag.Prefix))
{
ViewData.TemplateInfo.HtmlFieldPrefix = ViewBag.Prefix;
}
}
...
And I have this object in my model from my Edit view:
public List<ActionViewModel> actionList { get; set; }
Thanks in advance for your help :-)
Aucun commentaire:
Enregistrer un commentaire