And the action method ReadHikingDestination in the Surfacecontroller is executed:
[ChildActionOnly]
public ActionResult ReadHikingDestination(int? Id)
{
HikingDestinationViewModel model = new HkingDestinationViewModel();
if (Id == null)
{
//Codes
return PartialView("CreateHikingDestination", model);
}
else
{
//Codes
return PartialView("UpdateHikingDestination", model);
}
}
It can distinguish between which partial view to return since int is nullable, and I either get an empty partial form (without id - returns CreateHikingDestination), or a filled partial form (with id - returns UpdateHikingDestination).
But what if I want to distinguish between these two in the macro instead? How does it look like?
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{if (Id == null) // <<<< HOW TO FIND THIS ID (this don't work)?
{
@*actionName: ReadHikingDestination - controllerName: HikingDestinationSurface*@
@Html.Action("ReadHikingDestination", "HikingDestinationSurface")
}
else
{
@*actionName: ReadHikingDestinationById - controllerName: HikingDestinationSurface*@
@Html.Action("ReadHikingDestinationById", "HikingDestinationSurface")
}
}
Something like the macro above, which can distinguish between these two methods instead of, in the Surfacecontroller:
[ChildActionOnly]
public ActionResult ReadHikingDestination()
{
HikingDestinationViewModel model = new HikingDestinationViewModel();
//Codes
return PartialView("CreateHikingDestination", model);
}
[ChildActionOnly]
public ActionResult ReadHikingDestinationById(int Id)
{
HikingDestinationViewModel model = new HikingDestinationViewModel();
//Codes
return PartialView("UpdateHikingDestination", model);
}
<a href="/[email protected]"></a> is used to retrieve data from a single post to be edited (/turmaal without id is used to get a blank form). Should I rather use an ActionLink or other method instead of a regular a-tag in the view?
I think I understand the point here, but I have to combine RenderMacro and MacroParameters differently, as I've designed my page (with a combined create/update form abowe and a link list with update/delete below). I'll try if I can use a similar solution eventually. Either way, this is useful information that may be useful later.
My view looks like this. The macros CreateHikingDestination and ListHikingDestination are inside of a grid in this page. If the edit link in the list, the left side contains an Id (<a href="/[email protected]">), then the CreateHikingDestination macro is replaced with UpdateHikingDestination macro (macros and partial view got the same names):
NOTE: I may only point to the action ReadHikingDestination from macro CreateHikingDestination right now described at the top of the page now. I'm a bit uncertain right now. I've had little time to check through everything now at the writing moment. There is a lot of information to be written if I should display all the information in all macros, views and the surfacecontroller.
I guess I can't use @Umbraco.RenderMacro("someMacro", new {id = hikingdestination.Id}) inside of a grid, so I do not think this method can be used directly in my case. Is that right?
But I can also distinguish between create and update from the querystring, and then I found that this solution also works, and can distinguish between the two different action methods ReadHikingDestination and ReadHikingDestinationById.
This is now the content of partial view macro CreateHikingDestination, and partial view macro and macro UpdateHikingDestination becomes redundant (I have now renamed CreateHikingDestination to HikingDestinationForm since it now also contains update functionality).
How to get Id from view into macro?
I link from a page containing some partial views, with this link:
Then this link now hits one of the partial view with this macro partial view:
And the action method ReadHikingDestination in the Surfacecontroller is executed:
It can distinguish between which partial view to return since
int
is nullable, and I either get an empty partial form (without id - returns CreateHikingDestination), or a filled partial form (with id - returns UpdateHikingDestination).But what if I want to distinguish between these two in the macro instead? How does it look like?
Something like the macro above, which can distinguish between these two methods instead of, in the Surfacecontroller:
<a href="/[email protected]"></a>
is used to retrieve data from a single post to be edited (/turmaal without id is used to get a blank form). Should I rather use an ActionLink or other method instead of a regular a-tag in the view?In the developer menu you'll need to find your macro and add a parameter to is that is called id. Now in you'r Macro you can use
The only thing missing now is getting the parameter in the macro and that can be done like this:
Does this answer your question?
Thank you so much, I think so. I will give feedback as soon as I've tested this, but it may be over the weekend - no later than Monday. :-)
I think I understand the point here, but I have to combine RenderMacro and MacroParameters differently, as I've designed my page (with a combined create/update form abowe and a link list with update/delete below). I'll try if I can use a similar solution eventually. Either way, this is useful information that may be useful later.
How and where do you refer to your partial view macro? I thought you were using a partial view macro already.
My view looks like this. The macros CreateHikingDestination and ListHikingDestination are inside of a grid in this page. If the edit link in the list, the left side contains an Id (
<a href="/[email protected]">
), then the CreateHikingDestination macro is replaced with UpdateHikingDestination macro (macros and partial view got the same names):NOTE: I may only point to the action ReadHikingDestination from macro CreateHikingDestination right now described at the top of the page now. I'm a bit uncertain right now. I've had little time to check through everything now at the writing moment. There is a lot of information to be written if I should display all the information in all macros, views and the surfacecontroller.
Partial View ListHikingDestination:
The Updatelink is this link abowe:
I guess I can't use
@Umbraco.RenderMacro("someMacro", new {id = hikingdestination.Id})
inside of a grid, so I do not think this method can be used directly in my case. Is that right?But I can also distinguish between create and update from the querystring, and then I found that this solution also works, and can distinguish between the two different action methods ReadHikingDestination and ReadHikingDestinationById.
This is now the content of partial view macro CreateHikingDestination, and partial view macro and macro UpdateHikingDestination becomes redundant (I have now renamed CreateHikingDestination to HikingDestinationForm since it now also contains update functionality).
Are there any weaknesses in using querystring instead of macro parameters?
is working on a reply...