Url.Action How to add a parameter value from a model

In the controller, I have the "GetPhoto" action:

public FileResult GetPhoto(int id) { ... } 

Also, I have a Razor code where I am trying to dynamically add an ID parameter from a model:

 @model ISPIS.Models.KodFazeBiljke ... <img src="@Url.Action("GetPhoto", new { id = model.KodFazeBiljkeId })" alt="" width="250" height="190"/> 

However, it is not possible to write "id = model.KodFazeBiljkeId" because the model does not exist in the current context.

Any solution? Thanks!

+6
source share
1 answer

Your approach should work - you just need to turn to the uppercase model Model :

 <img src='@Url.Action("GetPhoto", new { id = Model.KodFazeBiljkeId })' alt="" width="250" height="190"/> 
+11
source

Source: https://habr.com/ru/post/956033/


All Articles