我有以下实体(域)对象和包含枚举的模型.显示名称正确显示并适用于EnumDropdownList但由于某些原因不适用于DisplayFor帮助程序,所有显示的都是实际的枚举名称.
不知道我缺少什么,asp.net MVC 5.1为此添加了显示名称支持,所以我不需要创建自己的帮助方法.请参阅:https://aspnet.codeplex.com/SourceControl/latest#Samples/MVC/EnumSample/EnumSample/Models/Enums.cs
public class Addon
{
public int Id { get; set; }
public AddonType AddonType { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public bool IsActive { get; set; }
}
public enum AddonType : byte
{
[Display(Name = "Cake Theme")]
CakeTheme,
[Display(Name = "Cake Flavour")]
CakeFlavour,
[Display(Name = "Cupcake Icing")]
CupcakeIcing,
[Display(Name = "Party Addon")]
AddOn
}
Run Code Online (Sandbox Code Playgroud)
模型
public class AddonModel
{
public …
Run Code Online (Sandbox Code Playgroud) 我不确定这是怎么发生或者为什么发生这种情况但是在google和stackoverflow上花了一天后我需要一些帮助来解决问题所在.
这是错误......
Server Error in '/' Application.
'object' does not contain a definition for 'Action'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'Action'
Source Error:
Line 15: else
Line 16: {
Line 17: string action = **Model.Action**;
Line 18: string returnUrl = Model.ReturnUrl;
Line 19: using …
Run Code Online (Sandbox Code Playgroud) 我有一个VSO(fka TFS)Git项目,可以正确构建和部署,但无法在解决方案中找到单元测试.
这是我看到的消息......
No test found. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
Run Code Online (Sandbox Code Playgroud)
在我的构建定义中,我指定
- Run tests in test sources matching **\Test*.dll, Target platform: 'X86'
Run Code Online (Sandbox Code Playgroud)
我的解决方案结构是这样的
/Tests.Unit.ProjectName/Tests.Unit.ProjectName.csproj
/ProjectName/ProjectName.csproj
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Hangfire在后台运行定期作业,轮询来自其他网站的数据,问题是如果上一个作业仍在运行,我不希望重复作业运行.
我已阅读文档,但似乎无法找到答案.有没有办法让一个每10分钟运行一次的重复工作,但如果之前的任务还没有完成则会跳过?
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
// Hangfire
GlobalConfiguration.Configuration
.UseSqlServerStorage("DatabaseContext");
app.UseHangfireDashboard();
app.UseHangfireServer();
RecurringJob.AddOrUpdate("site-parser", () => SiteParserService.RunAll(), Cron.Minutely, TimeZoneInfo.Utc);
ConfigureAuth(app);
}
Run Code Online (Sandbox Code Playgroud) 我一直在使用TuesPechkin一段时间了今天我将nuget包更新到新版本2.0.0+并注意到Factory.Create()不再解决,所以我去了GitHub读取所做的更改并注意到它现在期望到dll的路径?
IConverter converter =
new ThreadSafeConverter(
new PdfToolset(
new StaticDeployment(DLL_FOLDER_PATH)));
Run Code Online (Sandbox Code Playgroud)
在过去的几个小时里,我已经尝试了几乎所有我能想到的路径,"\ bin","\ app_data","\ app_start"等,我似乎无法找到或弄清楚它想要什么路径和什么DLL?
我可以在我的bin文件夹中看到TuesPechkin dll,这是我尝试的第一条路径,但是我收到以下错误:
其他信息:无法加载DLL'wkhtmltox.dll':找不到指定的模块.(来自HRESULT的异常:0x8007007E)
那个dll在哪里,现在我可以得到它,因为库似乎不包含它,我尝试安装TuesPechkin.Wkhtmltox.Win32包,但dll仍然无处可寻.另外我在asp.net网站项目中使用它,所以我假设使用以下内容应该可以用于获取路径,对吧?
var path = HttpContext.Current.Server.MapPath(@"~\bin\TuesPechkin.dll");
Run Code Online (Sandbox Code Playgroud)
这个问题一直是我周末的噩梦......我有一张表AddOrUpdate
不能正常工作,它不断添加,但从不更新.
我想要做的就是当我向表中添加一个新实体时,AddOrUpdate
我希望它检查AppointmentId
和CompletionCodeId
列,如果它们匹配而不是更新,否则添加.
表结构:
CREATE TABLE [dbo].[AppointmentCodes] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[AppointmentId] INT NOT NULL,
[Quantity] INT NOT NULL,
[CompletionCodeId] INT NOT NULL,
CONSTRAINT [PK_AppointmentCodes] PRIMARY KEY CLUSTERED ([Id] ASC, [AppointmentId] ASC));
Run Code Online (Sandbox Code Playgroud)
^^不确定这是否正确.
public void AddOrUpdate(T entity)
{
//uses DbContextExtensions to check value of primary key
_context.AddOrUpdate(entity);
Commit();
}
Run Code Online (Sandbox Code Playgroud)
方法
public void AddAppointmentCodes(List<AppointmentCode> appointmentCodes)
{
appointmentCodes.ForEach(x => _appointmentCodeRepository.AddOrUpdate(x));
}
Run Code Online (Sandbox Code Playgroud) 我无法找到或弄清楚如何获取物品清单(纸杯蛋糕)并在剃须刀中显示数量字段.
发生的事情是我无法获得列表中每个蛋糕数量的值.你能在Razor中做文本框数组吗?
视图
<div class="form-group">
<label>Cupcakes</label>
@foreach (var cupcake in Model.CupcakeList)
{
@Html.TextBox("CupcakeQuantities", cupcake.Id) @cupcake.Name <br/>
}
</div>
Run Code Online (Sandbox Code Playgroud)
模型
public List<Cupcake> CupcakeList { get; set; }
public List<int> CupcakeQuantities { get; set; }
Run Code Online (Sandbox Code Playgroud)
CONTROLLER
public ActionResult Create()
{
var model = new PartyBookingModel()
{
CupcakeList = db.Cupcakes.ToList(),
CupcakeQuantities = new List<int>()
};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
CUPCAKE(ENTITY)
public class Cupcake
{
public int Id { get; set; }
public string Name { get; set; }
public decimal PerDozen { get; set; …
Run Code Online (Sandbox Code Playgroud) 我们试图将用户密码作为安全字符串存储在注册表中,但我们似乎无法找到将其转换回纯文本的方法.这可以通过SecureString实现吗?
这是我们尝试使用的简单测试脚本......
Write-Host "Test Start..."
$PlainPassword = "@SomethingStupid" | ConvertTo-SecureString -AsPlainText -Force
$BSTR = ` [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PlainPassword)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Write-Host "Password is: " $PlainPassword
Read-Host
Run Code Online (Sandbox Code Playgroud)
这是我们得到的错误......
The term ' [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR'
is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\test.ps1:4 char:71
+ $BSTR = ` [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR
<<<< ($PlainPassword)
+ CategoryInfo : ObjectNotFound: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Windows服务创建一个WiX MSI安装程序,它将安装该服务但不启动它.我似乎无法找到解释如何做到这一点或任何可能的解释.
我试图删除我用于启动服务的ServiceControl以及在ServiceInstall上切换Start属性而没有任何运气.必须有可能做到这一点,对吗?我只是希望MSI文件安装该服务,并让用户在需要时启动它.
<Component Id="ServiceInstaller" Guid="9e578e3d-0339-425c-8633-f54ffaaa4921">
<ServiceInstall Id="ReportingServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="WindowsService.exe"
DisplayName="WindowsService"
Description="Wickedly awesome and amazing service."
ErrorControl="ignore"
Account="NT AUTHORITY\LocalService"
Start="auto"
Interactive="no" />
<ServiceControl Id="ServiceControl_Stop"
Name="WindowsService.exe"
Stop="both"
Remove="uninstall"
Wait="no" />
</Component>
Run Code Online (Sandbox Code Playgroud) 试图弄清楚为什么我的网站这么慢,它是一个使用引导主题的asp.net空模板。没有使用任何数据库或实体框架,所以我对为什么一个简单的asp.net网站这么慢感到困惑。
看来TTFB(至第一个字节的时间)已超过15-20秒。有时网站速度很快,但通常一段时间后网站会变慢,我的理解是IIS正在暂停应用程序池。
面临的挑战是我正在使用Host4Asp和GoDaddy托管,它们都存在此问题,并且由于它是共享托管,因此我无法访问IIS对其进行配置。我用PHP创建了相同的网站,并且每次都能立即加载。
我已经在webconfig中实现了缓存,并在所有控制器操作上使用了CacheOutput属性。
<system.webServer>
<staticContent>
<clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="public" />
</customHeaders>
</httpProtocol>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
因此,问题是当您对IIS的访问权限有限并且使用共享主机时,如何提高asp.net网站的TTFB,使其性能可比。当然,asp.net希望每个开发人员都拥有高性能的VPS或专用服务器。
如果有帮助,我已在GitHub上进行了存储库,其中包含完整的解决方案代码。 https://github.com/devfunkd/zenwire
c# ×7
asp.net ×3
asp.net-mvc ×2
razor ×2
azure-devops ×1
dll ×1
encryption ×1
enums ×1
foreign-keys ×1
git ×1
hangfire ×1
oauth-2.0 ×1
pechkin ×1
powershell ×1
sql ×1
sql-server ×1
unit-testing ×1
wix ×1
wkhtmltopdf ×1