The TopicBlock action returns an empty string ("") if the topic with the systemName doesn't exist; therefore, you can check the length of the content returned by Html.Action() to see if a topic exists.
@{ var topic = Html.Action("TopicBlock", "Topic", new { systemName = "TopicName" }); }
Thanks for you reply, however I don't know if I am missing somthing, but I was unable to make your code work, I kept getting an exception telling me that Html.Action("TopicBlock", "Topic", new { SystemName = Model.SeName.Replace("-", "") })) is not a string.
Anyway after further research I discoverd that Html.Action("TopicBlock", "Topic", new { SystemName = Model.SeName.Replace("-", "") })) is a MvcHtmlString and has the IsNullOrEmpty method, so my final solution is below.
@if (MvcHtmlString.IsNullOrEmpty(Html.Action("TopicBlock", "Topic", new { SystemName = Model.SeName.Replace("-", "") }))) { <p> Do Something</p> } else { <p> Do Nothing</p> }
The above solution is so that I can grab the product name and if there is a topic with the same product name with no spaces in the topic name then I display the topic.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Vous avez encore des questions ou avez besoin d'aide?