This is a migrated thread and some comments may be shown as answers.
How to reference model in @Url.Action in edit template
1 Answer 61 Views
This is a migrated thread and some comments may be shown as answers.
Jerry
Top achievements
Rank 1
Jerry asked on 02 May 2013, 05:03 PM
In my custom edit template, I'm trying to pass InventoryImageSeq from the model to an action on the controller.  This is used to retreive the image for the inventory item.

Here's my custom editor.  model.DeviceName displays correctly.  The <img... line does call GetImage in the controller, however inventoryImageSeq is always null.  
@model Copper.Domain.Entities.EntInventory
 
 
<div class="editor-label">
    @Html.LabelFor(model => model.DeviceName)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.DeviceName)
</div>
 
<div>
   <img alt="" src="@Url.Action("GetImage", "CellInventory", new { inventoryImageSeq = Model.InventoryImageSeq })" />
</div>

Here's GetImage in CellInventoryContoller.cs:

public FileContentResult GetImage(string inventoryImageSeq)
{
    EntInventoryImage entImage = new EntInventoryImage();
    int seq;
    if (Int32.TryParse(inventoryImageSeq, out seq))
    {
        entImage = _margoRepository.GetInventoryImage((int?)seq);
    }
    return File(entImage.ActualImage, entImage.ContentType);
}

Is this a problem with my syntax for the routeValues:

new { inventoryImageSeq = Model.InventoryImageSeq }

 or is something else wrong?

Thanks,

Jerry


1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 06 May 2013, 11:08 AM
Hello Jerry,

The main issue is that you are trying to reference the Model variable which is not available and it will not contain any concrete values inside of it.

You can try to render the Model.InventoryImageSeq directly and you will see nothing is displayed.

Inside of the editor template you can only use the different bindings of the MVVM

A way to construct the URL dynamically would be to use the edit event of the Grid , find that img tag and update its src attribute according to the model which should be available as argument of the event..

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jerry
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or