6

In controller I have the action "GetPhoto":

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

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

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

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

Any solution? Thanks!

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Branislav
  • 315
  • 1
  • 3
  • 13

1 Answers1

11

Your approach should work -- just have to refer to the model with the upper-case Model:

<img src='@Url.Action("GetPhoto", new { id = Model.KodFazeBiljkeId })' alt="" width="250" height="190"/>
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
  • Still not working! I got: Compiler Error Message: CS0135: 'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage.Model' – Branislav Oct 16 '13 at 00:15
  • @Branislav You might need to change code elsewhere in your view. See here: http://stackoverflow.com/a/6204388/1001985 – McGarnagle Oct 16 '13 at 00:19
  • Suppose in this case, if we change the value of KodFazeBiljkeId in some textbox, then will the Url.Action get updated according to with that value? – Anshul Dahiya Apr 17 '18 at 12:09