我有一個帶有剃鬚刀視圖引擎的asp.net mvc應用程序。我需要使用javascript
將c#中的列表轉換爲javascript中的表格
@section logout {
<a href='@Url.Action("Retour", "Client")'><img src="~/Content/images/home-icon.png" /></a>
<a href='@Url.Action("Logout", "Home")' style="margin-left: 91.6%"><img src="~/Content/images/images.jpg" style="width:37px; height:37px" /></a>
}
@Json.Encode(Model.Get_List_Tache());
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="~/Content/jquery.treeview.css" />
<script src="~/Content/jquery.cookie.js" type="text/javascript"></script>
<script src="~/Content/jquery.treeview.js" type="text/javascript"></script>
<script type="text/javascript" src="~/Content/demo.js"></script>
<!-- partie calendrier-->
<link rel="stylesheet" href="~/Scripts/Calendar/theme.css" />
<link href="~/Scripts/Calendar/fullcalendar.css" rel="stylesheet" />
<link href="~/Scripts/Calendar/fullcalendar.print.css" rel="stylesheet" media="print" />
<script src="~/Scripts/Calendar/fullcalendar.min.js"></script>
<style>
body
{
background-color:#eee;
}
#tree {
background-color:#eee;
}
.affaire {
color:black;
font-size: 16px;
}
.tache {
color:black;
font-size: 12px;
}
.projet {
color:blue;
font-size: 20px;
}
.sequence {
color:blue;
font-size: 13px;
}
#calendar {
width: 700px;
margin: 0 auto;
}
</style>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var titles= Json.Parse(Model.Get_List_Tache());
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: [
{
id: 999,
title: titles[0],
start: new Date(y, m, d - 3, 16, 0),
allDay: false
}
]
});
});
</script>
</head>
<body>
<table><tr><td style="width:200px;display:block;margin-top:80px;" id="tree">
<ul id="red" style="width: 100%; display:block;width:100%;margin-top:0%">
@for (int i = 0; i < Model.Get_List_Projet().Count; i++)
{
<li><span class="projet">Projet : @Model.Get_List_Projet()[@i].Description</span>
<br />
<br />
<ul>
@for (int j = 0; j < Model.Get_List_Affaire_By_Projet(Model.Get_List_Projet()[@i].Id_projet).Count; j++)
{
int id_affaire = @Model.Get_List_Affaire_By_Projet(Model.Get_List_Projet()[@i].Id_projet)[@j].Id_affaire;
<li><span class="affaire"> @Model.Get_List_Affaire_By_Projet(Model.Get_List_Projet()[@i].Id_projet)[@j].Affaire_description</span>
<br />
<br />
<ul>
@for (int k = 0; k < @Model.Get_List_Sequence_By_Affaire(id_affaire).Count; k++)
{
int id_sequence = @Model.Get_List_Sequence_By_Affaire(id_affaire)[k].Id_séquence;
<li><span class="sequence">@Model.Get_List_Sequence_By_Affaire(id_affaire)[k].Sequence_description </span>
<ul>
@for (int t = 0; t < @Model.Get_List_Tache_By_Sequence(id_sequence).Count; t++)
{
int id_tache = @Model.Get_List_Tache_By_Sequence(id_sequence)[t].Id_tache;
<li><span class="tache">Tache : @Html.ActionLink((string)@Model.Get_List_Tache_By_Sequence(id_sequence)[t].Tache_description, "GererTache", new { id = id_tache })</span></li>
}
<li>@Html.ActionLink("AjouterTache", "AjouterTache", new { id = id_affaire }) </li>
<li>@Html.ActionLink("GérerSéquence", "GererSequence", new { id = id_sequence }) </li>
</ul>
</li>
}
@for (int g = 0; g < @Model.Get_List_Tache_By_Affaire(id_affaire).Count; g++)
{
int id_task = @Model.Get_List_Tache_By_Affaire(id_affaire)[g].Id_tache;
<li><span class="tache">Tache: @Html.ActionLink((string)@Model.Get_List_Tache_By_Affaire(id_affaire)[g].Tache_description, "GererTache", new { id = id_task })</span>
</li>
}
</ul>
<ul><li>@Html.ActionLink("AjouterSéquence", "AjouterSéquence", new { id = id_affaire }) </li>
<li>@Html.ActionLink("AjouterTache", "AjouterTache", new { id = id_affaire }) </li>
<li>@Html.ActionLink("Gérer cette affaire", "GererAffaire", new { id = id_affaire }) </li>
</ul>
</li>
}
</ul>
</li>
}
<br />
</ul>
</td> <td >
<div id='calendar'></div>
</td>
</tr>
</table>
<a href='@Url.Action("Choice", "Travail")'>Retour</a>
</body>
</html>
爲在我看來,一個模型通過列表的值存儲,但我不知道我怎樣才能從服務器端傳遞到客戶端,從C#
名單通過Javascript
表。
所以我需要建議做這個任務
我不太清楚,我明白,對於服務器到Javascript,使用'@ this.Model.myVariable'和相反的,要麼'$ .post'數據使用'JSON.stringify'或創建一個窗體隱藏字段,其中'name'屬性與您的模型的屬性名稱匹配。 – NibblyPig
你的問題有點含糊。你有'List'你需要轉換成'事件數組'嗎? –
這裏我回答simmilar問題http://stackoverflow.com/questions/17485568/send-model-to-jquery/17485695#17485695 –