小编ter*_*ško的帖子

PHP类实例调用中的未定义变量通知

使用PHP,当我调用类的实例时,我会收到一个未定义的变量通知.我用其他语言编程,但不太熟悉PHP,你能不能看看我的代码并告诉我在定义类变量时的错误?谢谢.

<?php
    // create class Bike
    class Bike
    {
        // create variables for class Bike of price, max_speed, and miles
        var $price;
        var $max_speed;
        var $miles;

        // create constructor for class Bike with user set price and max_speed
        function __construct($price, $max_speed)
        {
            $this->price = $price;
            $this->max_speed = $max_speed;
        }

        // METHODS for class Bike:
        // displayInfo() - have this method display the bike's price, maximum speed, and the total miles driven
        function displayInfo()
        {
            echo "Price: $" . $price . …
Run Code Online (Sandbox Code Playgroud)

php debugging

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

MVC HTML.DropDownList设置宽度

我通过将它们放入ViewData并使用以下代码在View中显示它们来设置Controller中的下拉列表的LOV:

@Html.DropDownList("dropDown_"+item.ConfigCode);
Run Code Online (Sandbox Code Playgroud)

下拉列表显示我想要的,我现在卡在改变它的宽度.根据我在网上找到的内容,以下代码应该正常工作,但是,它没有显示下拉列表的任何值.我可以知道我应该怎么做吗?

@Html.DropDownList("dropDown_"+item.ConfigCode, Enumerable.Empty<SelectListItem>(),new {      @style = "width: 50px;" }) 
Run Code Online (Sandbox Code Playgroud)

html asp.net-mvc razor

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

C#使用资源文件进行验证消息

我正在开发一个asp.net MVC-4项目.我正在使用资源文件(.resx)进行国际化.我是第一次使用它,所以这个问题可能很愚蠢,很抱歉.

我已经创建了一个资源文件进行验证.我在我的项目中也创建了一些自定义验证.我的一个自定义验证是检查数组项长度,最大值和最小值.因此,如果验证失败,我必须显示验证消息:

数组长度必须小于5且大于1

现在我不想硬编码消息中的min(1)和max(5)值.那么有人可以告诉我如何在使用资源文件提供验证消息时实现这一目标?

c# asp.net-mvc asp.net-mvc-4

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

使用MVC中的JSON将数组从控制器发送到视图

我有这个代码:

var mapcity = new Array([]);              

         $.ajax({
             type: 'GET',
             url: '/home/DrawMap',
             dataType: 'json',
             success: function (data) {

                 var len = data.length;

                 for (var i = 0; i < len; i++) {

                    // mapcity['' + data[i].name + ''] = { center: new google.maps.LatLng(data[i].x, data[i].y), population: data[i].population, name: '' + data[i].name + '' };
                     mapcity['' + data[i].name + ''] = { center: new google.maps.LatLng(data[i].x, data[i].y), population: data[i].population, name: ''+data[i].name+'' };
                     //newarr[i] = data[i].name;

                   alert(mapcity[0].population)
                 }
                 }
         });
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码的一部分,这是来自控制器的功能:

public ActionResult DrawMap() …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc jquery json

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

使用部分为变量的名称调用php函数

我想问你一个简单的问题,

我有一个函数类叫做:

somethingModule()
someotherthingModule()
otherthingsModule()
Run Code Online (Sandbox Code Playgroud)

如何根据模式调用这些函数?我的意思是:

$call = $class->{$modulename}Module($params);
Run Code Online (Sandbox Code Playgroud)

php class

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

将十进制模型/重置文本框中的默认值设置为空白而不是mvc为0

我有两个问题围绕十进制文本框并向报表提交正确的值.这是带Razor的MVC 3 C#.

我的用户希望针对特定价格范围,起始价格范围和结束价格范围运行报告.两者都是模型中定义的十进制数据类型的文本框.它们也是可选的,因为用户可以选择其他一些参数,但我特别遇到了十进制类型的问题.加载视图时以及通过清除按钮重置时,两个文本框都默认为0.我需要在视图加载时以及重置时将其默认值设置为空白.我在视图中设置了以下内容,它可以很好地显示空白字段.

@Html.TextBoxFor(m => m.PriceRangeStart, new { @Value = (Model.PriceRangeStart > 0 ? Model.PriceRangeStart : 0) })  
Run Code Online (Sandbox Code Playgroud)

但是,唯一的问题是,当我尝试运行报告时它仍在寻找值,并在不需要运行报告时向用户提供"参数是必需的".有没有办法在幕后传递空值甚至0?

我不断搜索,并在模型中尝试了几个默认值选项,没有任何工作.我在视图中尝试了占位符.我试过HiddenFor字段.我尝试了以下类似的默认值:

public SellerActivityReport()
{
  decimal? a = null;
  PriceRangeStart = a.GetValueOrDefault(0m);
  PriceRangeEnd = a.GetValueOrDefault(0m);
}  
Run Code Online (Sandbox Code Playgroud)

我真的不想要回去改变所有这些只接受字符串,只有我不需要!如果这是可能的话,就完全卡住了.

c# asp.net-mvc razor

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

Html.Beginform 未在我的控制器中触发

我在 MVC 中使用 Html.Beginform 一段时间了,但现在遇到了一个奇怪的问题。我的表单上有 3 个提交按钮,它们应该触发 Html.Beginform 内的操作。问题是,它没有发射。我不知道这是我的观点结构还是我错过了一些东西。

这是我的观点:

<div id="maincontent" class="row select_sales"><!--CONTENT START-->
    <div id="page-title" class="text-blue col-md-12"><h2>Create DocPack : @Model.DocumentPackageNumber</h2></div>
    <div class="col-md-12">
      <ol class="breadcrumb">
        <li class="item1" style="color:#999999">Select Product</li>
        <li class="item2" style="color:#49afcd">Assign Manager and Planner</li>
        <li class="item3" style="color:#49afcd">Confirm DocPack</li>
      </ol>
    </div>
    <div id="dv-body-content" class="col-md-12"><br />
    @using (Html.BeginForm("CreateDocumentPackage", "home", FormMethod.Post))
    {
    <div id="select_product">
    <form class="form-horizontal col-md-7 col-md-offset-3" role="form">
      <div class="text-center">
         <div class="form-group">
            <label for="exampleInputEmail1">Select Product</label>
            <select class="form-control" style="margin:0 auto; width:300px !important;">
              <option>Standard Life</option>
            </select>
          </div>
           <div>
            <a href="~/home/index" class="btn btn-default">&nbsp;&nbsp;&nbsp;Back&nbsp;&nbsp;&nbsp;</a> …
Run Code Online (Sandbox Code Playgroud)

c# forms asp.net-mvc

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

mvc4在控制器中接收表单

我有一个HTML格式,我想将其提交给控制器

我试过的

@using (Html.BeginForm("RegisterApartmentOwner", "Home", FormMethod.Post, 
                            new { enctype = "multipart/form-data" }))
                            {
    <p>
        <label>First Name</label>
        <input type="text" placeholder="Enter your first Name" name="firstName" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Last Name</label>
        <input type="text" placeholder="Enter your last Name" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Password</label>
        <input type="text" placeholder="Enter your password" name="Password"/>
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Password Again</label>
        <input type="text" placeholder="Enter your password again" name="Password2"/>
        <span class="errorMessage"></span>
    </p>
    <p>
        <label>Mobile Number</label>
        <input type="text" placeholder="Enter your mobile number" />
        <span class="errorMessage"></span>
    </p>
    <p>
        <input type="submit" …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-4

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

多个IF/CASE语句的替代方案

有没有办法避免在C#中使用多个IF/CASE语句?

在我的应用程序中,我最终将有8个以上的字段用于创建Linq查询,其中每个表达式都可以为null或!= null,因此它将为我提供64个方案.

我没有提供任何代码示例,因为我可以使用IF/CASE并尽可能地简化它.

如果您熟悉这个问题的一些有用的方法,我将不胜感激任何建议.

代码示例(它只包括两个代理,但我必须添加更多的过滤数据)

知识库

    public virtual IEnumerable<T> Get(Expression<Func<T, bool>> filter = null, Expression<Func<T, bool>> filter1 = null)
            {
                IQueryable<T> query = dbSet;

                if (filter != null)
                {
                    query = query.Where(filter);
                    return query.ToList();
                }

                if (filter1 != null)
                {
                    query = query.Where(filter1);
                    return query.ToList();
                }
                else
               {
                    return query.ToList();
               }
            }
Run Code Online (Sandbox Code Playgroud)

调节器

public ActionResult Index(string searchFullName, string searchExtension)
    {
        var extensionList = new List<string>();
        var extensions = from n in unitofwork.DomainRepository.Get()
                         select n.Extension;
        extensionList.AddRange(extensions.Distinct());
        ViewBag.searchExtension = new SelectList(extensionList); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc if-statement switch-statement

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

c#中的访问者行为是值得怀疑的

是声明

public string FirstName;
Run Code Online (Sandbox Code Playgroud)

相当于

public string FirstName { get; set;}
Run Code Online (Sandbox Code Playgroud)

我相信没有区别,但我发现了以下内容:当我创建一个模型时 - 就像这样

public class Subject
{
    public string SubjectName;// { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

然后在MVC中使用表单发布此对象,我得到了SubjectName价值null.但是,如果我删除注释的访问器,那么我得到一个值.这种行为有什么理由吗?

c# asp.net-mvc field properties

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