Last post Aug 19, 2020 03:17 PM by bruce (sqlwork.com)
Member
3 Points
13 Posts
Aug 19, 2020 01:32 PM|klasss|LINK
My view index :
@{ foreach(var item in (List<AgendaModel>)ViewBag.ListaEventos) { @item.Id, @item.Title, @item.Start, @item.End, @item.AllDay, @item.Color, @item.TextColor; } }
This not work but this is one test.
I have similar this :
events.push({ 'id': 1, 'title': 'TESTE1', 'start': '2020-08-20 00:00:00', 'end': '2020-08-20 00:00:00', 'allday': false, 'color': '#FFFF00', 'textColor': '#000000' });
Where :
'@ViewBag.Id' = id
Thanks !
All-Star
58464 Points
15779 Posts
Aug 19, 2020 03:17 PM|bruce (sqlwork.com)|LINK
it is unclear what you are trying to do. while the "@" in razor is used to change to c# mode, in c# its the quote charter for reserved words
var @if = 0;
@{ foreach(var item in (List<AgendaModel>)ViewBag.ListaEventos) { <text> @item.Id, @item.Title, @item.Start, @item.End, @item.AllDay, @item.Color, @item.TextColor; </text> } }
will render the values with commas and trailing ;
if you where trying to initial a javascript array:
<script> @foreach(var item in (List<AgendaModel>)ViewBag.ListaEventos) { <text>events.push({ id: '@item.Id', title: '@item.Title', start: '@item.Start', end: '@item.End', allDay: '@item.AllDay', color: '@item.Color', testColor: '@item.TextColor'; });</text> } } </script>
but json serialize would be better
<script> var events = @Html.Raw ( JsonConvert.SerializeObject(ViewBad.ListaEvents, new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; }) ); </script>
this code makes no sense:
if the value of id is 10 then it renders
10 = id
Member
3 Points
13 Posts
Viewbag show in var
Aug 19, 2020 01:32 PM|klasss|LINK
My view index :
This not work but this is one test.
I have similar this :
Where :
'@ViewBag.Id' = id
Thanks !
All-Star
58464 Points
15779 Posts
Re: Viewbag show in var
Aug 19, 2020 03:17 PM|bruce (sqlwork.com)|LINK
it is unclear what you are trying to do. while the "@" in razor is used to change to c# mode, in c# its the quote charter for reserved words
var @if = 0;
will render the values with commas and trailing ;
if you where trying to initial a javascript array:
but json serialize would be better
this code makes no sense:
'@ViewBag.Id' = id
if the value of id is 10 then it renders
10 = id