简体   繁体   English

ASP.net MVC-从视图调用其他控制器

[英]ASP.net MVC - Call other controller from view

try to call from view in "Transaction" controller, The other "CreditCard" controller: 尝试从“交易”控制器中的视图调用,另一个“信用卡”控制器中的视图调用:

@(Url.Action("ShowImage", "CreditCard"))/" + ConcatString

from src propery of IMG tag. 来自IMG标签的src属性。 but because it from other controller the URL is invalid. 但由于来自其他控制器,因此该网址无效。 Insted Of: 插入的:

/creditcard/showimage/45809014157220320

Its: 它的:

/Transaction/TransactionToPDF/creditcard/showimage/45809014157220320

Wild guess, your Action doesn't accept a null for the image id? 大胆的猜测,您的操作是否不为图像ID接受null Rather than trying to add concatstring try specifying the parameter eg, 与其尝试添加concatstring尝试指定参数,例如,

@Url.Action("ShowImage", "CreditCard", new { ImageId= ConcatString }) 

Again, depending on what the allowed parameters are for the Action this should let the correct URL be resolved by the routing system 同样,根据操作允许的参数是什么,应该让路由系统解析正确的URL。

Of course you can use Html.Action helper. 当然,您可以使用Html.Action帮助器。 But it is easier for me to do it like this. 但是,对我来说,这样做比较容易。

   <img src="/CreditCard/ShowImage/@ConcatString" class="img float-xs-right" width="350" height="380" id="creditCardImage" /> 

I think you have an "Area" issue. 我认为您遇到了“区域”问题。 If they are in different areas, you should be able to do this: 如果它们在不同的区域,则应该可以执行以下操作:

@(Url.Action("ShowImage", "CreditCard", new { area = "" }))/" + ConcatString

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC - 如何从视图中调用 Controller 方法以重定向到多个其他视图? - ASP.NET MVC - How do I Call a Controller Method from within a View to Redirect to Multiple Other Views? 如何从 ASP.NET Core MVC 中的一个控制器调用或返回另一个控制器的视图 - How to call or return the view of another controller from one controller in ASP.NET Core MVC ASP.NET MVC 4从另一个控制器调用一个控制器方法 - ASP.NET MVC 4 call a controller method from another controller ASP.Net MVC:如何使用列表 ViewData object 或从 controller 传递到视图的其他复杂对象 - ASP.Net MVC: How to use a List ViewData object or other complex objects passed from a controller to a view ASP.NET MVC-从不同的视图/控制器调用相同的存储过程 - ASP.NET MVC - call the same stored procedure from a different view/controller 从同一控制器ASP.NET MVC3重定向以查看或调用void方法 - Redirecting to view or call void method from same controller ASP.NET MVC3 如何使用 ASP.NET MVC C# Html 从视图中调用控制器中的函数 - How to call a function in the controller from the view using ASP.NET MVC C# Html 从控制器中的存储库中调用方法(ASP.NET MVC) - Call method from repository in controller (ASP.NET MVC) 从控制器ASP.NET MVC调用表单OnFailure处理程序 - Call form OnFailure handler from controller, ASP.NET MVC 如何从asp.net MVC 4中的按钮单击调用控制器 - How to call controller from the button click in asp.net MVC 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM