小编Hri*_*kan的帖子

如何在C#中生成一个随机的10位数字?

我正在使用C#,我需要生成一个随机的10位数字.到目前为止,我很幸运找到了表明最小值的例子.我将如何生成一个10位数的随机数,可以从0开始,(最初,我希望,random.Next(1000000000,9999999999)但我怀疑这是我想要的).

我的代码现在看起来像这样:

    [WebMethod]
    public string GenerateNumber()
    {
        Random random = new Random();
        return random.Next(?);
    }
Run Code Online (Sandbox Code Playgroud)

**更新结束了这样做,

    [WebMethod]
    public string GenerateNumber()
    {
        Random random = new Random();
        string r = "";
        int i;
        for (i = 1; i < 11; i++)
        {
            r += random.Next(0, 9).ToString();
        }
        return r;
    }
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net random

20
推荐指数
4
解决办法
6万
查看次数

在javascript中用于验证的正则表达式为1-10

数字1-10和1-5的正则表达式是什么?请帮助这个陷入困境的灵魂.

javascript regex

8
推荐指数
1
解决办法
1万
查看次数

使用jQuery从下拉列表中删除除第一个值之外的所有值

             if (questions[0]) {
                 $("select[id$=ddlPollQuestions] > option").remove();
                 $('#ddlPollQuestions').append('<option value="">Choose a question to compare to</option>');
                 $.each(questions, function(i, question) {
                     $('#ddlPollQuestions').append('<option value="' + question.QUESTIONID + '">' + question.TEXT + '</option>');
                 });
             } else {
                 $("select[id$=ddlPollQuestions] > option").remove();
                 $('#ddlPollQuestions').append('<option value="' + 0 + '">' + 'There are no questions of this type' + '</option>');
             }
Run Code Online (Sandbox Code Playgroud)

它的作用是删除所有以前的值,但是我想要第一个选项,即"选择一个问题..."保留,然后显示"没有问题..."作为我的第二个选项.我的代码在这里没有显示"选择一个问题.."作为第一个选项.谢谢你看看!

html c# asp.net asp.net-mvc jquery

6
推荐指数
2
解决办法
7958
查看次数

允许在我的登录表单MVC上访问我的Site.Css

我需要我的CSS显示我的登录页面,但它现在没有显示.如何允许访问包含css的登录页面?我使用表单身份验证,我的web.config文件的代码块如下所示:

<authentication mode="Forms">
  <forms loginUrl="UserAccount/Login" defaultUrl="UserAccount/Index" timeout="60"></forms>
</authentication>
<authorization>
  <deny users="?"/>
  <allow users="*"/>
</authorization>
Run Code Online (Sandbox Code Playgroud)

我的site.css位于我的/Content/Site.css路径中.如何添加它以允许所有用户访问此文件?

html asp.net-mvc

4
推荐指数
1
解决办法
3308
查看次数

在Ajax/jQuery中功能'成功'

我在使用Ajax调用的成功函数显示值时遇到问题.我的代码如下.

$.ajax({
    type: "POST",
    url: "http://localhost/practical 8/checkuser.php",
    data: form_data,
    success: function(response)
    {
        if(response == 'success'){
            $("#errorUsername").html("<label class='error'>"+response+"</label>");
        }else if(response == 'fail'){
            $("#errorUsername").html("<label class='error'>"+response+"</label>");
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

我的checkuser.php基本上回声"成功"或"失败".

ifelse如果我的成功函数语句不工作.但是这样做

$.ajax({
    type: "POST",
    url: "http://localhost/practical 8/checkuser.php",
    data: form_data,
    success: function(response)
    {
            $("#errorUsername").html("<label class='error'>"+response+"</label>");
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

工作得很好.我究竟做错了什么?

javascript php ajax jquery

3
推荐指数
1
解决办法
5274
查看次数

提交时,不传递表单中隐藏div标签的值

我有javascript来控制在检查状态下隐藏或显示的某些div标签.然后我在提交表单时传递这些值.事实上,div标签中隐藏的字段的值也会被传递.我怎么不传递这些值?

我的HTML/Javascript如下:

<div id="divShortAnswerQuestion">
    <h2>Short Answer Question</h2>
    <!--Question Order-->
    <asp:Label ID="Label2" runat="server" Text="Question Order"></asp:Label>
    <%=Html.TextBox("QuestionOrder")%>
    <br />
    <!--Partial Answers-->
    <asp:Label ID="Label5" runat="server" Text="Allow Partial Answers"></asp:Label>    
    <%=Html.RadioButton("PartialAnswers", "1", true) %>Yes
    <%=Html.RadioButton("PartialAnswers", "0", false) %>No
    <br />
    <!--Max Answers-->
    <asp:Label ID="Label6" runat="server" Text="Max Answers (1-10)"></asp:Label> 
    <%=Html.TextBox("Max") %>
    <br />         
    <!--Data Type-->
    <asp:Label ID="Label7" runat="server" Text="Data Type"></asp:Label>
    <%=Html.DropDownList("DataType", new List<SelectListItem>
                     {
                        new SelectListItem{Text="Numeric", Value = "Numeric"}, 
                        new SelectListItem{Text="Alphanumeric", Value = "Alphanumeric"},
                        new SelectListItem{Text="Date", Value = "Date"}
                     }) %>
    <br />
    <!--Question Type-->                         
    <asp:Label …
Run Code Online (Sandbox Code Playgroud)

html javascript asp.net-mvc jquery

3
推荐指数
1
解决办法
4862
查看次数

无法序列化System.Linq.IQueryable接口

我遇到了一个错误,"无法序列化System.Linq.IQueryable接口." 当我尝试在我的Web服务中运行我的方法时.我的班级是这样的:

        public class AirlineSearchStrong
    {
        public Flight_Schedule flightSchedule { get; set; }
        public Flight_Schedule_Seats_and_Price flightScheduleAndPrices { get; set; }
        public Airline airline { get; set; }
        public Travel_Class_Capacity travelClassCapacity { get; set; }

    }

    [WebMethod]
    public IQueryable SearchFlight(string dep_Date, string dep_Airport, string arr_Airport, int no_Of_Seats)
    {        
        AirlineLinqDataContext db = new AirlineLinqDataContext();
        var query = (from fs in db.Flight_Schedules
                     join fssp in db.Flight_Schedule_Seats_and_Prices on fs.flight_number equals fssp.flight_number
                     join al in db.Airlines on fs.airline_code equals al.airline_code
                     join altc in db.Travel_Class_Capacities on …
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net-mvc

3
推荐指数
1
解决办法
3499
查看次数

Javascript正则表达式检查值是否以数字开头,后跟其他任何内容

我将如何进行正则表达式,看它是否以数字开头,任何字符都可以跟随.我现在的表达是

var validaddress = /^[0-9][A-Za-z0-9]+$/;
Run Code Online (Sandbox Code Playgroud)

但这不是正确的方法.我是新手,帮助任何人?

javascript jquery

2
推荐指数
1
解决办法
8236
查看次数

html helper下拉列表在我的视图中显示硬编码值,而不是数据库中的值

我希望能够显示一个下拉列表,该下拉列表的值不是来自我的数据库,而是具有稍后将用于执行插入查询的硬编码值.我该怎么做呢?

<%=Html.DropDownList("Chart Type", "Horizontal") %>
Run Code Online (Sandbox Code Playgroud)

我需要值Horizo​​ntal,Vertical,Pie在下拉列表中.

任何帮助深表感谢!

html model-view-controller asp.net-mvc

2
推荐指数
1
解决办法
1万
查看次数

DateTime.now使用数据库中的值减法

我需要能够从我的数据库中获取当前日期与日期的差异.如果差异为30,我需要显示到期日期消息.我的代码块看起来像这样:

var expiryDate = DateTime.Now - DateTime.Parse(user[3]);
Run Code Online (Sandbox Code Playgroud)

问题是,这会返回一些我似乎无法管理的奇怪数字.我怎样才能获得天数,然后检查它是否是30天?

谢谢你好好看看!

.net html c# asp.net

1
推荐指数
1
解决办法
677
查看次数

使用StreamReader从文本文件中读取新行

我存储在我的文件中的是与帐户相关的值.(只是测试,不会在商业上使用).我需要的是通过遍历每一行来绘制用户名和密码的值,但.peek()似乎对我不起作用.我究竟做错了什么?我的块看起来像这样:

        public string CheckAccount(string username, string password)
    {
        StreamReader sr;
        string filename = "H:\\AccountInfo.txt";
        string s;
        string result = "";
        sr = File.OpenText(filename);
        s = sr.ReadLine();
        string usernameFromText;
        string passwordFromText;
        while (sr.Peek() >= 0)
        {
            usernameFromText = (s.Split(','))[0];
            passwordFromText = (s.Split(','))[2];
            if (username == usernameFromText && password == passwordFromText)
            {
                result = "Successfully Logged in!";
            }
            else if (username != usernameFromText || password != passwordFromText)
            {
                result = "Your Username / Password is Invalid!";
            }
        }
        sr.Close();

        return result;
    } …
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net

0
推荐指数
1
解决办法
4501
查看次数

MVC删除操作链接不起作用

我的Action链接如下所示:

<%= Html.ActionLink("Delete Message", "DeleteMessage", new { messageId=item.MESSAGEID })%>
Run Code Online (Sandbox Code Playgroud)

我的控制器中的Action看起来像这样:

    [AcceptVerbs(HttpVerbs.Delete)]
    public ActionResult DeleteMessage(int messageId)
    {

        Message message = context.Messages.FirstOrDefault(m => m.MESSAGEID.Equals(messageId));
        if (message != null)
        {
            context.Messages.DeleteOnSubmit(message);
            context.SubmitChanges();
        }
        return View();
    }
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,我的模型中的项目仍然没有被删除.我哪里出错了?

asp.net-mvc html.actionlink

0
推荐指数
1
解决办法
940
查看次数