我在我的razor 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()
部分视图包含一个调用操作的备忘录框和按钮:
@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()
我正在尝试在服务器端(在我的控制器上的操作中)获取在此框中键入的文本。在我的应用程序的其他地方,我已经能够使用以下代码来获取控件的值:
public ActionResult ResolveReview(bool Pass)
{ ...
EditorExtension.GetValue<string>("txtReviewComment")
...}
但是在此方案中返回null。在popupcontrol中呈现的局部视图中从控件获取此值的正确方法是什么?
答案 0 :(得分:1)
通常,有必要在表单容器中包装编辑器,以便在提交时传递整个表单的内容。然后,可以使用标准模型绑定机制来检索所需编辑器的值。使用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")
}
或
public ActionResult ResolveReview(string txtReviewComment) { ... }
答案 1 :(得分:0)
我自己找到了答案,我的按钮导致GET方法而不是POST。通过设置&#34; UseSubmitBehavior&#34;在我的保存按钮上为true,它开始触发POST功能并允许执行
EditorExtension.GetValue<string>("txtReviewComment")
获取值的行。