c# - 内联编辑验证

标签 c# validation asp.net-mvc-4 kendo-grid inline-editing

我有一个剑道网格。我想在那里添加内联编辑验证。

下面是我的剑道网格的屏幕截图:

enter image description here

According to my functionality i want to validate the "Media" filed according to "Media Type" field.

We have 4 Media Types(Email,WebURL,Facebook,Twitter).

And the Media field string should be according to selected Media Type.For example:

1) For Email Media Type :   amit@gmail.com
2) For WebURL Media Type:   www.yahoo.com

And if someone entered invalid Media string according to selected Media Type then i want to show validation message.It can be MVC model validation or Javascript validation.

I have tried with two know ways.But none of helping me.

1) 客户端模板。

In which i have used client template for Add Net Item button to validate the Media field.And for that i have handle it by Javascript function.Please have a look below :-

.ToolBar(commands => { commands.Template("添加新媒体"); })

By this i was able to validate the field.But was unable to save it in database.Means i don't know the way to call Saving method by this.

2) 通过命令:-

我也试过这个:-

.ToolBar(commands =>
                       {
                           commands.Create();
                           commands.Save();
                       })

但它没有验证该字段。但我能够将其保存在数据库中。

最佳答案

你可以在下拉更改事件中做到这一点

看看这个 fiddle

将人员“Dave”更改为软件工程师以查看验证工作。

你可以自定义 onSelect 事件中的验证

function onSelect(e) {

var name = $('td:first', $(e.sender.element).closest("tr")).text();
var dataItema = this.dataItem(e.item.index());

if ((this.dataSource.data()[e.item.index()].title) == 'Software Engineer') {
    if (name == 'Dave') {
        $('td:first', $(e.sender.element).closest("tr")).addClass('error');
    }
}

//var id = e.item.find("span").attr("data-id");

}

关于c# - 内联编辑验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18009624/

相关文章:

asp.net - MVC4 在单个 View 上显示多个部分 View 的问题

c# - 将 comboBox 设置为自定义显示格式

c# - C# 编译器是否设置版本或平台常量?

c# - 如何绘制Windows经典风格的窗口元素

c# - 在不破坏文件系统或文化的情况下将 URL 规范化为小写?

JavaScript 输入字段必须等于 JavaScript 代码中隐藏的数字

c# - 将数据导出到 CSV MVC4

javascript - 验证输入仅包含数字和点后的小数

laravel - 使用正则表达式允许字母字符、连字符、下划线、空格和数字

c# - ApiController 中的 Request.AnonymousID