Update hits this action from another url named "/rediger-turmaal" and works as it should:
[HttpPost]
[NotChildAction]
// Submit button: Partial Views UpdateHikingDestination.cshtml
public ActionResult UpdateHikingDestination(HikingDestinationViewModel model)
{
// Object reference not set to an instance of an object.
try
{
if (Members.IsLoggedIn() && Members.IsMemberAuthorized(allowTypes: new[] { "hiker" }))
{
// Servervalidate fields
if (model.StartDate.ToString().Length < 1) { ModelState.AddModelError("", "Angi startdato for turmål"); }
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
//nodeId same value as nodeId in db table cmsMember
model.nodeId = Members.GetCurrentMemberId();
model.SelectedHikingDestination = model.SelectedHikingDestination;
model.Title = model.Title;
model.StartDate = model.StartDate;
model.HikingCode = model.HikingCode;
//Get the Umbraco db
var db = ApplicationContext.DatabaseContext.Database;
//Update the object to the DB
db.Update(model, model.Id);
//All done - redirect to the page
ModelState.Clear();
return Redirect("/turmaal");
}
TempData["updateSuccess"] = true;
return CurrentUmbracoPage();
}
catch (NullReferenceException ex)
{
// Maybe also servervalidate?
ModelState.Clear();
return CurrentUmbracoPage();
}
}
But don't know why exactly this action was executed, and how model and model.Id was found.
Delete hit this action now, and it's no surprice (and it works):
[HttpGet]
public ActionResult DeleteHikingDestination(int Id, int redirectId)
{
// Object reference not set to an instance of an object.
try
{
if (Members.IsLoggedIn() && Members.IsMemberAuthorized(allowTypes: new[] { "hiker" }))
{
HikingDestinations.DeleteById(Id);
}
TempData["deleteSuccess"] = true;
return RedirectToUmbracoPage(redirectId);
}
catch (NullReferenceException ex)
{
ModelState.Clear();
return CurrentUmbracoPage();
}
}
But how can I specify the link to use this action instead (similar to UpdateHikingDestination that works)?
[HttpPost]
[NotChildAction]
// Submit button: Partial Views UpdateHikingDestination.cshtml
public ActionResult DeleteHikingDestination(HikingDestinationViewModel model)
{
// Object reference not set to an instance of an object.
try
{
if (Members.IsLoggedIn() && Members.IsMemberAuthorized(allowTypes: new[] { "hiker" }))
{
//Get the Umbraco db
var db = ApplicationContext.DatabaseContext.Database;
//Delete the DB-object
db.Delete(model.Id);
//All done - redirect to the page
ModelState.Clear();
return Redirect("/turmaal");
}
TempData["deleteSuccess"] = true;
return CurrentUmbracoPage();
}
catch (NullReferenceException ex)
{
// Maybe also servervalidate?
ModelState.Clear();
return CurrentUmbracoPage();
}
}
How to send a model from view to controller? With Id I find correct action, but not with model.
Can I use @Url.SurfaceAction for both change and delete buttons/links?
I have tried these two, but didn't make them work (how should they be written?):
public static string SurfaceAction(this UrlHelper url, string action, string controllerName, object additionalRouteVals);
public static string SurfaceAction<T>(this UrlHelper url, string action, object additionalRouteVals) where T : SurfaceController;
I need to get more control of which action is being taken, also because I need to extend the controller with another delete action to confirm that members really want to delete the item before deleting.
Then I got this message:
"The parameters dictionary contains a null entry for parameter 'Id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult DeleteHikingDestination(Int32, Int32)' in 'Neoweb.Controllers.HikingDestinationSurfaceController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters"
So it looks like it hits the same Action as before (I wrote { model = Model }, but that's maybe wrong)?
Passing model from view to surfacecontroller
Partial view inside of @using (Html.BeginUmbracoForm
Update hits this action from another url named "/rediger-turmaal" and works as it should:
But don't know why exactly this action was executed, and how
model
andmodel.Id
was found.Delete hit this action now, and it's no surprice (and it works):
But how can I specify the link to use this action instead (similar to UpdateHikingDestination that works)?
How to send a model from view to controller? With Id I find correct action, but not with model.
Can I use @Url.SurfaceAction for both change and delete buttons/links?
I have tried these two, but didn't make them work (how should they be written?):
I need to get more control of which action is being taken, also because I need to extend the controller with another delete action to confirm that members really want to delete the item before deleting.
Hi Tom,
just wild guessing to be honest but if this works:
have you tried using:
maybe that works too?
Regards David
Hi David.
Then I got this message: "The parameters dictionary contains a null entry for parameter 'Id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult DeleteHikingDestination(Int32, Int32)' in 'Neoweb.Controllers.HikingDestinationSurfaceController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters"
So it looks like it hits the same Action as before (I wrote { model = Model }, but that's maybe wrong)?
is working on a reply...