简体   繁体   中英

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. 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? Rather than trying to add concatstring try specifying the parameter eg,

@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

Of course you can use Html.Action helper. 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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM