我試圖在複選框被選中時顯示Kendo UI文本編輯器。
但是它不工作,你能幫幫我..剃刀與kendoui文本編輯器
@if (Model.IsAlert!=true)
{
<td>
@(Html.Kendo().Editor().Name("Explanation").HtmlAttributes(new { style = "display:show" }))
</td>
}
我試圖在複選框被選中時顯示Kendo UI文本編輯器。
但是它不工作,你能幫幫我..剃刀與kendoui文本編輯器
@if (Model.IsAlert!=true)
{
<td>
@(Html.Kendo().Editor().Name("Explanation").HtmlAttributes(new { style = "display:show" }))
</td>
}
您當前的做法只會渲染/在屏幕上的初始負載評估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:顯示空白:前「:」顯示:無「}))它工作? – Radha
我相信應該有效,儘管@style需要有一個;在每種風格之間列出,所以「display:show; white-space:pre;」將是你想如何格式化它的一部分。試試看!! :) –
您目前的方法只會在屏幕初始加載時評估Model.IsAlert!= true ...您可能想要實現一些javascript/jquery以基於該值來隱藏/顯示文本框嗎? –
謝謝你somuch Dinglemeyer,你的接近正在工作... :) – Radha
如果它的工作,請隨時標記爲答案:)很高興你得到它的工作! –