我现在正在学习 JavaFx 和 MVC,我正在尝试通过控制器将按钮连接到模型。我尝试了很多使用方法,button.setOnActive(EventHandler e);
但它在视图类之外不起作用,那么正确的方法是什么?
这是我的视图类
public class View extends Application{
private TextField num1;
private Label addLabel;
private TextField num2;;
public Button calcB;
private TextField sol;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Calculator");
num1 = new TextField();
addLabel = new Label("+");
num2 = new TextField();
calcB = new Button("Calculate");
**// I'm trying to use this in the Controller
calcB.setOnAction(event -> System.exit(0));**
sol = new TextField();
FlowPane flowPane = new FlowPane();
flowPane.getChildren().addAll(num1, addLabel, num2, calcB, sol);
Scene scene = …Run Code Online (Sandbox Code Playgroud) java model-view-controller javafx event-handling eventhandler
我在 mvc razor 中使用剑道图
@(Html.Kendo().Chart().Name("chart"))
Run Code Online (Sandbox Code Playgroud)
使用这个js和cs文件
<link href="~/Scripts/kendo.dataviz.default.min.css" rel="stylesheet" />
<link href="~/Scripts/kendo.default.min.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/jquery.min.js"></script>
<script src="~/Scripts/kendo.all.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
想象一下,在 laravel 构造函数(PostController)中,我需要注入 3 个模型:User、Post 和 Comment。
我有两种情况:
1)将这 3 个模型全部注入控制器构造函数中,然后我在具体函数中使用此控制器变量,如下所示:$this->post
2)无论何时何地需要(例如index(Post $post)),将这些模型注入具体控制器的功能中;
这两种做法哪个更好?在第一种情况下,在索引函数中我只使用$this->post变量,但我也创建$this->comment变量,$this->user因为我在其他函数中需要它们?但我不需要它们在索引中,所以每当我通过寻址索引特定路由来调用索引时,我都会注入并创建它们。那不是很糟糕吗?那么这些哪个更好呢?
我尝试通过 ajax post 请求使用验证防伪令牌,但响应是找不到根元素。我删除了防伪令牌,它工作得很好。
这是我的代码:javascript;
function Save() {
let GroupName = GetElementValue("GroupName");
let GroupId = GetElementValue("GroupId");
var Group = {
__RequestVerificationToken: gettoken(),
GroupId: :1",
GroupName: "My Group Name"
};
if (IsFormValid("GroupForm")) {
AjaxPost("/Groups/AddGroup", Group).done(function () {
GetGroups();
});
}
}
function gettoken() {
var token = '@Html.AntiForgeryToken()';
token = $(token).val();
return token;
}
function AjaxPost(url, data) {
return $.ajax({
type: "post",
contentType: "application/json;charset=utf-8",
dataType: "json",
responseType: "json",
url: url,
data: JSON.stringify(data)
});
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个:
$.ajax({
type: "POST",
url: "/Groups/AddGroup",
data: …Run Code Online (Sandbox Code Playgroud) javascript c# model-view-controller asp.net-ajax asp.net-core
我定义了一个自定义IViewLocationExpander来检查多租户 Web 应用程序中特定于站点的视图。
想象一下有两个租户 WebsiteA 和 WebsiteB 以及HomeController和Index View的以下文件结构
我的 IViewLocationExpander 将为 WebsiteA 呈现Views/Home/WebSiteA/Index.cshtml ,为 WebsiteB 呈现Views/Home/Index.cshtml - 因为没有特定于 WebsiteB 的索引视图,因此它使用默认视图。
我还在视图中设置了一个名为“Common”的文件夹来保存任何部分视图 - 这个想法是我可以以相同的方式呈现自定义部分视图(例如标题)。
这是我的IViewLocationExpander的代码
public sealed class TenantViewLocationExpander : IViewLocationExpander
{
private ITenantService _tenantService;
private string _tenant;
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
string[] locations =
{
"/Views/{1}/" + _tenant + "/{0}.cshtml",
"/Views/Common/" + _tenant + "/{0}.cshtml",
"/Views/Shared/" + _tenant …Run Code Online (Sandbox Code Playgroud) 对于某些应用程序,我需要一个自定义授权策略提供程序,并点击此链接,并能够成功创建一个在控制器中工作的授权策略提供程序。现在,当涉及到视图时,在基于角色的授权中,您可以简单地使用该术语@if (User.IsInRole("SomeRole"))来显示或隐藏 div 和资源。
如何在视图中使用自定义授权策略提供程序来确定给定用户是否可以根据策略评估查看内容?
我搜索了网络,找不到有关它的有用信息,并尝试与
@if ((await AuthorizationService.AuthorizeAsync(User, "PolicyName")).Succeeded)
Run Code Online (Sandbox Code Playgroud)
但这也并不成功——它也不是一项政策。
以前有人这样做过吗?
我在控制器中使用自定义策略提供程序,如下所示:
[MinimumAgeAuthorize(15)]
public IActionResult Index()
{
//some code
}
Run Code Online (Sandbox Code Playgroud)
我不能做
@if ((await AuthorizationService.AuthorizeAsync(User, "MinimumAgeAuthorize(15)")).Succeeded)
Run Code Online (Sandbox Code Playgroud)
在剃刀视图中它的等价物是什么?
c# model-view-controller authorization asp.net-authorization asp.net-core-mvc
在我的表单中,我有两个被禁用的输入,因为用户必须使用我在视图上制作的键盘来填充它们。但是,当我提交表单时,对象到达时其参数为 0(因为它们是数字)。我知道它是禁用标签导致这种情况发生的,因为当我删除标签时,值会被初始化。
这些是我的输入:
<td>@Html.EditorFor(model => model.Cliente, new { htmlAttributes = new { disabled = "true" } })</td>
Run Code Online (Sandbox Code Playgroud)
我怎样才能禁用它们并同时将值发送到控制器?
据我了解,值类型隐式具有[Required]属性 whenMvcOptions.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes设置为false。但坦率地说,当我在两者之间切换时,我看不出有什么区别。
此外,如果我[Required]在不可空类型(例如 an )上显式使用该属性int,则需要我设置其值,而不是仅在没有给定int参数的情况下命中端点,该参数将为其类型分配默认值- 0.
所以,总结一下:
如果它隐式添加[Required]属性,为什么显式变体提供完全不同的功能?
启用/禁用有任何功能差异吗MvcOptions.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes?据我所知,它没有改变任何东西。
c# model-view-controller model-validation data-annotations asp.net-core
我在 MVC 应用程序中使用 Kendo Grid。
@(Html.Kendo().PanelBar().Name("panelbar").ExpandMode(PanelBarExpandMode.Single).SelectedIndex(0).Items(panelbar =>
{
panelbar.Add().Encoded(false).Text("<div Customer </div>").Content(@<div>
@(Html.Kendo().Grid(Model).Name("grid_messageGroup").Columns(columns =>
{
columns.Bound(f => f.Title).Title("TitleName");
columns.Bound(f => f.Message).Title("MessageTitle");
columns.Bound(f => f.MessageBoard).Hidden().IncludeInMenu(false);
})
.Events(e => e.CustomEvent)
.Reorderable(reoder => reoder.Columns(true))
.HtmlAttributes(new { @class = "styleCSS" })
.Sortable(sortable => sortable.AllowUnsort(false))
.ColumnMenu(columnMenu => columnMenu
.Messages(columnMenuMessages => columnMenuMessages
.SortAscending(SortAscending)
.SortDescending(SortDescending)
.Columns(Columns)
.Filter(Filter)
)
)
.Selectable().Sortable().Filterable(filterable => filterable.Extra(true)
.Messages(messages => messages.Filter(Filter).Clear(Clear).Info(Info))
.Operators(operators => operators.ForString(str => str.Clear().Contains(ContainsColumnFilterOperator)).ForEnums(en => en.Clear().IsEqualTo(EqualsColumnFilterOperator)))).Resizable(resize => resize.Columns(true))
.ClientDetailTemplateId("template")
.DataSource(dataSource => dataSource.Ajax().ServerOperation(false))
.Filterable(filterable => filterable.Extra(false).Operators(operators => operators.ForString(str => str.Clear().Contains(ContainsColumnFilterOperator))
.ForDate(d => d.Clear().IsEqualTo(EqualsColumnFilterOperator) …Run Code Online (Sandbox Code Playgroud) 我有 PostController,这是它的方法store()。
public function store(Request $request)
{
$this->handleUploadedImage(
$request->file('upload'),
$request->input('CKEditorFuncNum')
);
$post = Post::create([
'content' => request('content'),
'is_published' => request('is_published'),
'slug' => Carbon::now()->format('Y-m-d-His'),
'title' => $this->firstSentence(request('content')),
'template' => $this->randomTemplate(request('template')),
]);
$post->tag(explode(',', $request->tags));
return redirect()->route('posts');
}
Run Code Online (Sandbox Code Playgroud)
方法handleUploadedImage()现在存储在 PostController 本身中。但我将在其他控制器中使用它。我应该把它移到哪里?不在 Request 类中,因为它与验证无关。不在 Models/Post 中,因为它不仅适用于 Post 模型。对于服务提供者类来说,它并不是那么全局的函数。
方法firstSentence()和randomTemplate()也存储在该控制器中。它们只会在其中使用。也许我应该将它们移到模型/帖子中?那么,到底如何在 method 中调用它们store()(更具体地说,在 method 中create())?
我阅读了该理论,并且(希望)理解了瘦控制器和胖模型的概念,但我需要针对此示例提供一些实用的具体建议。您能否建议移动到哪里以及如何调用这些方法?
c# ×5
asp.net-core ×3
kendo-ui ×2
laravel ×2
php ×2
asp.net-ajax ×1
controller ×1
eventhandler ×1
forms ×1
java ×1
javafx ×1
javascript ×1
jquery ×1
model ×1