我有一个像表单一样工作的视图,因此它加载一堆下拉列表并从ActionResult Index. 将所有数据输入表单后,我将使用Html.BeginForm("Create"调用 save 方法。的ActionResult Create(RequestForm model)。所以问题是我想使用两种模型,一种用于加载,一种用于保存数据。我现在正在做的是从 FormViewModel 和 RequestForm 模型中获取对象。
有一个更好的方法吗?
看法:
@model FormViewModel
@using (Html.BeginForm("Create", "RequestForm", FormMethod.Post))
{
@Html.ValidationSummary(true);
<div class="k-content">
<h4>* Country</h4>
@Html.TextBoxFor(x => x.CountryId, new { id = "ddlCountry", @class = "form-control" })
@Html.ValidationMessageFor(model => model.CountryId)
</div>
}
Run Code Online (Sandbox Code Playgroud)
窗体视图模型
[Required]
public int? CountryId { get; set; }
public List<CountryModel> ListOfCountries { get; set; }
Run Code Online (Sandbox Code Playgroud)
申请表模型
public class RequestForm
{
[Required]
public int? CountryId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器
public …Run Code Online (Sandbox Code Playgroud) 目标:根据用户在 ASP.NET Identity 中的角色隐藏某些元素,例如页面链接。
我尝试过的:[Authorize(Roles = IdentityHelper.Administrator)]
(如果您将注释放在某些元素(例如页面)上,这确实会限制对某些元素的访问,但它不会隐藏元素本身。我希望它同时执行这两项操作。)对用户隐藏这些元素并不完全重要,因为它们已经受到限制,但这将使我的网站对用户来说看起来更好。
(IdentityHelper 只是一个帮助程序类,用于设置有关管理员角色的所有详细信息)
代码示例:
//Restricts access, which is good, but does not completely hide elements from user.
[Authorize(Roles = IdentityHelper.Administrator)]
public async Task <IActionResult> Edit(int id)
{
//get pixel art with corrosponding id
PixelArt p = await PixelDBManager.GetSinglePixelAsync(id, _context);
//pass pixel art to view
return View(p);
}
Run Code Online (Sandbox Code Playgroud)
我是否应该切换到基于声明或策略的身份而不是角色,或者我可以坚持使用角色来解决这个特定问题吗?
asp.net model-view-controller asp.net-mvc asp.net-identity asp.net-core
我在 Visual Studio 2019 中创建了一个新的 MVC Web 应用程序项目(针对 .NET 5.0)
现在我想安装EntityFrameworkCore,但当我在NuGet管理器中搜索时它没有出现在列表中。如果我输入“entity”,则只会出现 3 个选项。如果我输入的内容更多,则不会再出现任何内容。
我也尝试输入(在控制台管理器中)
Install-Package Microsoft.EntityFrameworkCore -Version 5.0.11
Run Code Online (Sandbox Code Playgroud)
并收到此错误:
`Install-Package : NU1101: Unable to find package`
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packag
es
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore -Version 5.0.11
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Run Code Online (Sandbox Code Playgroud)
我还多次尝试清理和构建该项目。我最近刚安装的VS2019。可能出了什么问题?
asp.net-mvc entity-framework visual-studio asp.net-core visual-studio-2019
我希望能够判断用户是否按下了Ctrl+[something] 或EscGo 中的键盘。该程序在终端内的 Linux 环境中运行。
我正在使用RichTextBox(.NET WinForms 3.5) 并想覆盖一些标准的 ShortCut 键......例如,我不希望Ctrl+I通过 RichText 方法使文本变成斜体,而是运行我的自己处理文本的方法。
有任何想法吗?
我希望读取 JSON 文件并使用该信息来创建多项选择测验。我只是无法理解如何从 JSON 文件中实际读取它。我已经设法读对了问题的数量,但仅此而已。
这是我的 JSON 文件的当前布局:
{
"numOfQues": 5,
"questions": [
{
"question": "Who is the US President?",
"options": [
"Joe Biden",
"Joe BIREN",
"Joe Momma",
"Joe Bein"
],
"answer": 2
},
{
"question": "Who scored the best goal in Puskas history?",
"options": [
"Erik Lamela",
"Son Heung-Min",
"Cristiano Ronaldo",
"Wayne Rooney"
],
"answer": 4
},
{
"question": "Where should Lamela really have finished?",
"options": [
"First",
"Second",
"Third",
"Fourth"
],
"answer": 3
},
{
"question": "What does …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
asp.net-core ×2
c# ×2
asp.net ×1
c++ ×1
go ×1
json ×1
keyboard ×1
linux ×1
raw ×1
razor ×1
richtextbox ×1
terminal ×1
winforms ×1