提交时不会刷新随机数

时间:2017-03-28 11:10:20

标签: html asp.net asp.net-mvc

我有一个随机数生成器(用于凭证编号),但是当我单击该按钮时,不会显示新的随机数。有人可以帮忙吗?

这是我的控制器,它生成随机数:

   static Random random = new Random();
   public List<string> RandomVouchers()
    { 
        int vouchersToGenerate = 1;
        int lengthOfVoucher = 10;
        List<string> generatedVouchers = new List<string>();
        char[] keys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890".ToCharArray();

        while (generatedVouchers.Count < vouchersToGenerate)
        {
            string voucher = GenerateVoucher(keys, lengthOfVoucher);
            if (!generatedVouchers.Contains(voucher))
            {
                 generatedVouchers.Add(voucher);
                 return generatedVouchers; 
            }
        }
        return generatedVouchers;
    }

    private static string GenerateVoucher(char[] keys, int lengthOfVoucher)
    {
        return Enumerable
            .Range(1, lengthOfVoucher) // for(i.. ) 
            .Select(k => keys[random.Next(0, keys.Length - 1)])  // generate a new random char 
            .Aggregate("", (e, c) => e + c); // join into a string
    }

这是订单页面:

<div id="vouchercode" style="display:none">
<ul>
    @foreach (string strVouchers in ViewBag.Vouchers)
    {
        <li>@strVouchers</li>
    }
</ul></div>
<button id="getvoucher">GenerateVoucher</button> 

这是javascript代码:

<script type="text/javascript">
$(function () {
    $("#getvoucher").click(function () {
        $("#vouchercode").dialog({
            width: 460,
            height: 200,
            modal: true,
        }); 
    });
});

0 个答案:

没有答案