这个问题可能已经被回答了数百次,但是这里有.
我有这个代码块:
private void PopulateStringDropdownList(List<ObjectInfo> listObject,
object selectedType = null)
{
List<string> listString = listObject.OrderBy(x => x.m_Type).ToString();
for (int i = 0; i < listString .Count; i++)
{
for (int j = i + 1; j < listString .Count; j++)
{
if (String.Equals(listString [i], listString [j]))
{
listString.RemoveAt(j);
}
}
}
ViewBag.property1 = new SelectList(listString );
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我正在尝试使用来自参数中传递的列表中包含的每个对象的属性的字符串来填充下拉列表.
但是由于你在那里看到的错误,代码无法编译,我还没理解为什么.有人帮忙吗?
我正在开发一个应用程序,我正在思考一些事情.所以我想我会问这里有经验的人告诉我他们对此的看法.
所以我有这个控制器(存储控制器),它很庞大,有很多方法,Get和Post动作等等.它工作得很好,但我还处于开发阶段.
我想知道什么是最好的做法:拥有这个控制器,它拥有如此多的方法和动作,或者将方法分成多个控制器?让一个控制器处理几乎所有方法或许多控制器是理想的吗?
在您询问之前,是的,我的商店控制器中的所有内容都与"商店相关".但在我的商店里我有物品,包裹等等.
编辑
感谢大家!根据你的建议,我将我的巨大Store控制器分成了较小的控制器:一个用于物品,一个用于包装,依此类推.这确实使代码更具可读性.此外,提供的大量评论将使我有望升级,所以非常感谢!
在我的控制器中,我根据用户首先选择的参数过滤列表。它就像一个搜索引擎。
该列表有可能返回 0 个值。虽然这不是错误,但我想显示某种消息,例如错误消息,但到目前为止我发现的只是在 c# 中使用 ModelState 或 ModelStateDictionary,这也需要异常。但这也不例外,只是一个条件,所以我有点不解。
我将写出一些代码,以便您直观地看到我想要的内容:
if(listOBJS.count == 0)
{
// DISPLAY THE ERROR!
PopulateDDL1();
PopulateDDL2();
return View(listOBJS);
}
Run Code Online (Sandbox Code Playgroud)
对,就是我想做的事情。我怎么能继续?谢谢你的建议。
大多数时候,当我使用数据库相关对象时,我的工作方式如下:
// Declare a private static variable of my database
private static BlueBerry_MTGEntities mDb = new BlueBerry_MTGEntities();
Run Code Online (Sandbox Code Playgroud)
然后,在任何方法(示例)中:
public StoreInfo GetStoreByID(int _storeID)
{
using (mDb = new BlueBerry_MTGEntities())
{
mDb.Database.Connection.Open();
// Bla bla stuff to return the proper StoreInfo Object.
}
}
Run Code Online (Sandbox Code Playgroud)
以这种方式工作以避免汇集崩溃并开发高效的MVC Asp.Net应用程序是一种好习惯吗?如果没有,那么什么是好的做法,你会怎么做?
我试图理解COBOL程序的行为,我绊倒了以下几行:
PERFORM 525-NUMERIC THRU 525-EXIT
VARYING K FROM 1 BY 1 UNTIL K > CAR-L.
Run Code Online (Sandbox Code Playgroud)
我理解全球概念,它是基于价值的某种循环K,但我不明白这些THRU 525-EXIT词的影响?
我目前正在使用 C# 和 Visual Studio 2012 开发一个项目。
我很难弄清楚为什么 VS 2012 不想运行我的所有测试。
我有一个测试项目,它运行 2 个单元测试中的 1 个。无论我尝试过什么,它都不想运行另一个单元测试。未通过测试资源管理器检测到,“未运行”测试不包含该文件。
这是一个基本框架,可以清楚地说明:
(我已经编辑了框架以包含解决方案的每个部分)
Solution
MainProject
ProjectA.Tests (that is the project)
UnitTestsA.cs (Actually run)
UnitTestsB.cs (Neven run)
Run Code Online (Sandbox Code Playgroud)
这是第二个单元测试文件的代码:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MagicAdmin.Tests
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{ }
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我做错了什么?
我需要一种方法来转换像这样的特殊字符:
Helloæ
正常人物.所以这个词最终会成为Helloae.到目前为止,我已经尝试过HttpUtility.Decode,或者将UTF8转换为win1252的方法,但没有任何效果.是否有一些简单而通用的东西可以完成这项工作?
谢谢.
编辑
我尝试使用OC上的帖子来实现这两种方法.这是方法:
public static string ConvertUTF8ToWin1252(string _source)
{
Encoding utf8 = new UTF8Encoding();
Encoding win1252 = Encoding.GetEncoding(1252);
byte[] input = _source.ToUTF8ByteArray();
byte[] output = Encoding.Convert(utf8, win1252, input);
return win1252.GetString(output);
}
// It should be noted that this method is expecting UTF-8 input only,
// so you probably should give it a more fitting name.
private static byte[] ToUTF8ByteArray(this string _str)
{
Encoding encoding = new UTF8Encoding();
return encoding.GetBytes(_str);
}
Run Code Online (Sandbox Code Playgroud)
但它没有奏效.字符串保持不变.
在我的数据库中,我有一个具有以下属性的项目列表:
public System.DateTime CARD_OF_DAY_DATE_CREATED { get; set; }
Run Code Online (Sandbox Code Playgroud)
CARD_OF_DAY_DATE_CREATED我需要获取最接近使用 c#的项目DateTime.Now。我可以做大量的 for/foreach 循环,但我想知道是否有一个好的、有效的方法来做到这一点?
注意:该CARD_OF_DAY_DATE_CREATED字段只需向前检查,这意味着检查是否是CARD_OF_DAY_DATE_CREATED昨天是不相关的,因为这些项目不会出现在列表中。
我在Visual Studio项目文件中有几种可能的配置.如何指定默认选择哪一个(当不.suo存在时)?现在,当我在Visual Studio中打开项目时,默认情况下会选择调试配置.
项目文件的相关部分:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>...</ProductVersion>
<SchemaVersion>...</SchemaVersion>
<ProjectGuid>{...}</ProjectGuid>
<OutputType>...</OutputType>
<RootNamespace>...</RootNamespace>
<AssemblyName>AAAAA</AssemblyName>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>Full</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>false</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DocumentationFile>AAAAA.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\</OutputPath>
<DocumentationFile>AAAAA.xml</DocumentationFile>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我希望默认选择此配置:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>Full</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>false</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DocumentationFile>AAAAA.xml</DocumentationFile>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud) 出于开发目的,我们需要通过 Visual Studio 在本地启动 PowerShell 脚本,其任务是获取特定分支的最后一个构建 ID。
到目前为止,我已经尝试了很多基于此的选择:
$WebClient = New-Object Net.WebClient
Write-Host "Downloading patches and binaries"
Write-Host "Get ID"
$url = "https://oldrepo.visualstudio.com/ProjectA/_apis/build/latest/14?branchName=master"
$result = $WebClient.DownloadString($url)
Write-Host $result
Run Code Online (Sandbox Code Playgroud)
但是,该result值返回 azure 的登录页面,而不是我的存储库。如果我将相同的网址粘贴到浏览器中,我确实会得到好的页面。
我认为请求中传递了某种 cookie/AD 凭据,但我没有通过开发人员工具看到任何相关内容。
我尝试手动设置 WebClient 对象的凭据,如下所示:
#$creds = Get-Credential -UserName "User" -Message "Login"
#$WebClient.Credentials = $creds
#$WebClient.UseDefaultCredentials = $true
Run Code Online (Sandbox Code Playgroud)
但无济于事。我缺少什么?
c# ×7
asp.net-mvc ×4
list ×2
.net ×1
asp.net ×1
azure-devops ×1
cobol ×1
datetime ×1
mstest ×1
powershell ×1
string ×1
unit-testing ×1