Kendo-MVC How to compare viewbag value to a template kendo listview to create new divs

1 Answer 80 Views
Application ListView
Karthey
Top achievements
Rank 1
Karthey asked on 19 Sep 2021, 10:57 PM

Hi , Creating Bot like application using kendo list view.

If the Current logged in user Name is matched with exiting comment , then create div and align left else align div right. Not able to do in a template.

Please help:

Thanks

Karthey

 

 

1 Answer, 1 is accepted

Sort by
0
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 22 Sep 2021, 07:49 PM

Hello Karthey,

One way in which you can set the Kendo UI template to be conditional based on the ViewBag value is to set the if/then statement in a similar way like this template:

<script type="text/x-kendo-template" id="commentRowTemplate">
     <div>
         <div class="rowname">#:data.CategoryID #</div>
            # if ( data.CategoryID ==  @ViewBag.eventCurrentUser ) { #
              
                <div class="chat-message-right">
                     <span>#=data.ProductName # </span>
                </div>
                <br/>
                <br/>
            #} else {#
                 <div class="chat-message-left">
                     <span>#=data.ProductName # </span>
                  </div>
                <br/>
                <br/>

            #}#
        </div>
    </div>
</script>

Please take a look at the attached sample which utilizes the approach above.  Please feel free to modify the styling based on your preferences, and let me know if you have any questions.  

Regards,
Patrick
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Application ListView
Asked by
Karthey
Top achievements
Rank 1
Answers by
Patrick | Technical Support Engineer, Senior
Telerik team
Share this question
or