One thing you can do is to assign the dictionary (your Feeds
Property value) to a javascript variable and then you can access it in your client side script.
If your Feeds
property is of type Dictionary<int,string>
, you will get something like this in your feeds property.
{1: "StringVal1", 2: "StringVal2"}
From this javascript object, you can access your dictionary item value using the key.
Code for your razor view will be
@using Newtonsoft.Json
@model YourNameSpaceHere.YourViewModelTypeHere
<script type="text/javascript">
$(function() {
var feeds = @Html.Raw(JsonConvert.SerializeObject(Model.Feeds));
console.log(feeds);
var feedId = 2; // replace with real value to check
alert(feeds[feedId]);
});
</script>
Alternatively , you may consider making an Ajax call with the feed id to an end point which returns the complex object you want.