【问题标题】:How to call javascript function in view in C# code on if else condition如何在 if else 条件下在 C# 代码中调用 javascript 函数
【发布时间】:2019-09-13 14:53:02
【问题描述】:
    @foreach (var item in outcode)
                   {
             var outc = item;
             if (!codedata.Contains(outc))
             {
                 codedata.Add(outc);
             }
             else
             {
                 Fun();

             }
    }
//this is my C# code and here else condition call JavaScript function.

 function fun() {
                $("table").append('<tr><th><button class="btn btn-secondary" type="button">@Session["dd"]</button> </th> </tr>');
            }

// 这是 JavaScript 函数。 以及在剃刀代码中执行 else 条件时调用此函数。

【问题讨论】:

标签: javascript c# asp.net-mvc


【解决方案1】:

希望对你有帮助

<script type="text/javascript">

    function fun()

    {

    alert('You clicked '+ name +"!");

    }

    </script>

    <div>

        <table class="table table-bordered table-condensed">

            <tr>

                <th>Name</th>

                <th>Department</th>

                <th>Action</th>

            </tr>

            @foreach (Employee emp in Model)

            {

                <tr>

                    <td>

                        <a onclick="AlertName('@String.Format("{0} {1}", emp.FirstName, emp.LastName)')" href="#">@String.Format("{0} {1}", emp.FirstName, emp.LastName)</a>   

                    </td>

                    <td>



                    </td>


                </tr>

            }

        </table>

    </div>

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2022-01-24
    • 2018-10-16
    • 2019-04-25
    相关资源
    最近更新 更多