gpt4 book ai didi

c# - 在 asp.net mvc 应用程序中从 Javascript 访问 C# 变量

转载 作者:数据小太阳 更新时间:2023-10-29 04:37:07 24 4
gpt4 key购买 nike

我在 How to use javascript variables in C# and vice versa 中遇到问题:我将这个 Model 传递给 View :

public List<Tache> Get_List_Tache()
{
Equipe _equipe = new Equipe();
List<Tache> liste_initiale = _equipe.Get_List_tache();
return liste_initiale;
}

这是一个对象列表 Tache,我想在其中使用它的三个字段 Tache_descriptionBegin_dateEnd_date.

在我的 JavaScript 代码中我有这个函数并且它工作正常:

       <script>

$(document).ready(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
theme: true,
header: {left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'},
editable: true,
events: [
@foreach (var m in Model.Get_List_Tache())
{
@:{title : @m.Tache_description , start: @m.Begin_date , end : @m.Begin_date }
}
]

});
});

</script>

数组events的值只是为了测试,我需要用Model的值填充events。对于这样的每个元素:title = Tache_descriptionstart = Begin_dateend = End_date

那么我该如何完成这个任务呢?有什么建议吗?

最佳答案

试试这个,

foreach (var item in YourList)
{
events: [{ title: '@item.title', start: '@item.start', end: '@item.end'}]
}

因此,在此代码中只需替换您的模型实体的名称。

关于c# - 在 asp.net mvc 应用程序中从 Javascript 访问 C# 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17671385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com