How to reference model in @Url.Action in edit template

2 posts, 0 answers
  1. Jerry
    Jerry avatar
    4 posts
    Member since:
    Jul 2010

    Posted 02 May 2013 Link to this post

    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 class="editor-field">
        @Html.EditorFor(model => model.DeviceName)
       <img alt="" src="@Url.Action("GetImage", "CellInventory", new { inventoryImageSeq = Model.InventoryImageSeq })" />

    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?



  2. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 06 May 2013 Link to this post

    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!
Back to Top