简体   繁体   English

DevExpress MVC编辑器在Controller上获得价值

[英]DevExpress MVC Editors get value on Controller

I have a popupcontrol declared in my razor cshtml file as follow: 我在剃刀cshtml文件中声明了一个popupcontrol,如下所示:

    @Html.DevExpress().PopupControl(settings =>
{
settings.Name = "popSendBackReview";
settings.HeaderText = "Send Review Back to Scheduler";
settings.AllowResize = false;
settings.ShowHeader = true;
settings.ShowOnPageLoad = false;
settings.AllowDragging = true;
settings.CloseAction = CloseAction.CloseButton;
settings.CloseOnEscape = false;
settings.Modal = true;
settings.PopupElementID = "popSendBackReview";
settings.AutoUpdatePosition = true;
settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
settings.Height = 280;
settings.Width = 450;

settings.SetContent(() =>
{
    Html.RenderPartial("_SendBackReviewPanel");
});
}).GetHtml()

The partial view contains a memo box and button that calls an action: 局部视图包含一个备注框和一个调用动作的按钮:

@Html.DevExpress().Memo(settings =>
{
settings.Width = 300;
settings.Height = 150;
settings.Style.Add("margin-bottom", "10px");
settings.Name = "txtReviewComment";
settings.Properties.ValidationSettings.RequiredField.IsRequired = true;
settings.Properties.ValidationSettings.RequiredField.ErrorText = "A Review Comment is Required.";
settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.Text;
settings.Properties.ValidationSettings.ErrorTextPosition = ErrorTextPosition.Bottom;
settings.Properties.ValidationSettings.Display = Display.Dynamic;
settings.Properties.ValidationSettings.ValidationGroup = "Review";
}).GetHtml()

@Html.DevExpress().Button(settings =>
{
settings.Name = "btnSaveReview";
settings.Text = "Send Back for Scheduler Review";
settings.UseSubmitBehavior = false;
settings.ValidationGroup = "Review";
settings.RouteValues = new { Controller = "Matter", Action = "ResolveReview", Pass = false, Comment = Model.CommentText };
}).GetHtml()

@Html.DevExpress().Button(settings =>
{
settings.Name = "btnCancelReview";
settings.Text = "Cancel";
settings.UseSubmitBehavior = false;
settings.ClientSideEvents.Click = "function(s,e) { popSendBackReview.Hide(); }";
}).GetHtml()

I am trying to get the text that is typed into this box on the server side (in the action on my controller). 我正在尝试获取在服务器端(在控制器上的操作中)在此框中键入的文本。 In other places in my application I have been able to use the following code to get values of controls: 在我的应用程序的其他地方,我已经能够使用以下代码来获取控件的值:

public ActionResult ResolveReview(bool Pass)
{ ...
EditorExtension.GetValue<string>("txtReviewComment")
...}

However this returns null in this scenario. 但是,在这种情况下,此方法返回null。 What is the correct way to get this value from a control in a partial view rendered in a popupcontrol? 从popupcontrol呈现的部分视图的控件中获取此值的正确方法是什么?

In general, it is necessary to wrap editors within a form container in order to pass the entire form's content on submit. 通常,有必要将编辑器包装在表单容器中,以便在提交时传递整个表单的内容。 Then, it is possible to retrive the required editor's value using the standard Model Binding mechanism. 然后,可以使用标准的“模型绑定”机制来检索所需的编辑器的值。 When using DevExpress MVC Editors, make sure that the DevExpressEditorsBinder is registered: 使用DevExpress MVC编辑器时,请确保已注册DevExpressEditorsBinder

@using(Html.BeginForm("ResolveReview")) {
    @Html.DevExpress().Memo(settings => {
        settings.Name = "txtReviewComment";
    }).GetHtml()

    @Html.DevExpress().Button(settings => {
        settings.Name = "btnSaveReview";
        settings.UseSubmitBehavior = true;
    }).GetHtml()
}

public ActionResult ResolveReview(bool Pass) {
    EditorExtension.GetValue<string>("txtReviewComment")
}

or 要么

public ActionResult ResolveReview(string txtReviewComment) { ... }

Check the MVC Data Editors - Model Binding and Editing learning resource. 检查“ MVC数据编辑器-模型绑定和编辑”学习资源。

I found the answer on my own, my button was causing a GET method to fire instead of POST. 我自己找到了答案,我的按钮导致触发GET方法而不是POST。 By setting "UseSubmitBehavior" to true on my save button, it started firing the POST function and allowing the 通过在我的保存按钮上将“ UseSubmitBehavior”设置为true,它开始触发POST功能并允许
EditorExtension.GetValue<string>("txtReviewComment")

line to get a value. 行以获取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM