【问题标题】:Razor with kendoui text editor带有 kendoui 文本编辑器的剃刀
【发布时间】:2017-02-14 21:47:58
【问题描述】:

我试图在选中复选框时显示 Kendo UI 文本编辑器。
但是它不起作用,您能帮帮我吗..

@if (Model.IsAlert!=true)
{
  <td>                   
     @(Html.Kendo().Editor().Name("Explanation").HtmlAttributes(new { style = "display:show" }))             
  </td>
}

【问题讨论】:

  • 您当前的方法只会在屏幕初始加载时评估 Model.IsAlert != true...您可能希望实现一些 javascript/jquery 来根据值隐藏/显示文本框?
  • 非常感谢 Dinglemeyer,您的方法现在正在运行... :)
  • 如果它有效,请随时将其标记为答案 :) 很高兴您成功了!

标签: razor kendo-ui kendo-asp.net-mvc


【解决方案1】:

您当前的方法只会在初始加载屏幕时呈现/评估 Model.IsAlert。

我建议删除 if 语句,并将此 td 默认为隐藏,然后通过映射到复选框控件的 onChange 事件处理程序根据模型中的属性进行更改。

<td id="thingToHide" hidden="hidden">
 @(Html.Kendo().Editor().Name("Explanation").HtmlAttributes(new { style = "display:show" }))             
</td>

还有一些jquery代码:

<script type="text/javascript">
 $(document).ready(function () { // On page load method, check model and show textbox if needed
      var model = @Html.Raw(Json.Encode(Model)); // get model example is taken from http://stackoverflow.com/questions/16361364/accessing-mvcs-model-property-from-javascript
      if (model.IsAlert) { // If model IsAlert is true, show Explanation field
           $("#thingToHide").show();
      }
 });

 $("#YourCheckBoxId").on("change", function() {
     $("#thingToHide").toggle();
 });
</script>

祝拉达好运!

【讨论】:

  • 非常感谢您的回复,我可以这样写吗,因为我是剑道和剃须刀的新手,我怀疑我们是否可以在 .HtmlAttributes(new {condition}) 中写一个条件......................... @(Html.Kendo().EditorFor(model => model.Explantion).HtmlAttributes(new { @style= Model.IsAlert ? "display:show white-space: pre" :"display:none"})) 有用吗?
  • 我相信这应该可行,尽管@style 需要有一个 ;在其中列出的每个样式之间,因此“显示:显示;空白:前;”将是您希望如何格式化它的那一部分。试试看!! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-25
相关资源
最近更新 更多