I have two partial views that has the same model, I am using devexpress callbacks. My question is if I can know in my controller function which partial view made the callback and then render it? Or I need to duplicate the function and just render in each function the correct partial view?
Your view returns to you only that you pass into it. So, you should pass your view-name into the hidden field container, as an example, and then read this value from the server side. Someone already answered how to pass view name , I will try to extend this answer.
First of all, you need to create some view-path parsing extension
public static class IViewExtensions
{
public static string GetViewName(this IView view)
{
string viewUrl = String.Empty;
if (view is BuildManagerCompiledView)
{
viewUrl = ((BuildManagerCompiledView)view).ViewPath;
}
else
{
throw new InvalidOperationException("Buld manager is not defined!");
}
string viewFileName = viewUrl.Substring(viewUrl.LastIndexOf('/'));
string viewFileNameWithoutExtension = Path.GetFileNameWithoutExtension(viewFileName);
return (viewFileNameWithoutExtension);
}
}
Then pass your each view-names into the form container
@using ViewExtensionNamespace;
<input type="hidden" id="ViewName" name="ViewName" value="@Html.ViewContext.View.GetViewName()" />
And read it from the server side
name = Request.Params["ViewName"];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.