加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 03:50:27 所属栏目:asp.Net 来源:网络整理
导读:我在如何在C#中使用 javascript变量时遇到问题,反之亦然:我将此模型传递给视图: public ListTache Get_List_Tache(){ Equipe _equipe = new Equipe(); ListTache liste_initiale = _equipe.Get_List_tache(); return liste_initiale;} 这是一个对象列表Tac
我在如何在C#中使用 javascript变量时遇到问题,反之亦然:我将此模型传递给视图:

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

这是一个对象列表Tache,我想在其中使用它的三个字段Tache_description,Begin_date和End_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>

数组事件的值仅用于测试,我需要通过模型的值填充事件.对于这样的每个元素:title = Tache_description,start = Begin_date和end = End_date.

那我该怎么做呢?有什么建议?

解决方法

在javascript中制作一个foreach剃刀循环:

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
    theme: true,events: [
    @
    {
      bool isFirst = true;
    }
    @foreach(var m in Model)
    {
        if(!isFirst)
        {
          @:,}

        @:{title: @m.Tache_description,...<other properties here>}

        isFirst = false;
    }
    ]
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读