Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url.Action How to add parameter value from the model

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!

like image 862
Branislav Avatar asked Oct 16 '13 00:10

Branislav


1 Answers

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"/>
like image 124
McGarnagle Avatar answered Sep 19 '22 11:09

McGarnagle