如何使用Razor ASp.NET MVC连接HTML元素的ID [英] How to concatenate the id of the HTML element using Razor ASp.NET MVC

查看:168
本文介绍了如何使用Razor ASp.NET MVC连接HTML元素的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有复选框的网格列,我想给他们一个不同的ID. ID基于模型中的CustomerId.我应该使用什么语法来连接chk_@item.CustomerId.

I have a grid column with checkboxes and I want to give them a different id. Id is based on the CustomerId in the Model. What syntax should I use to concatenate the chk_@item.CustomerId.

// using the telerik grid 
id="chk_@item.OrderNumber"  // does not work 

//这会将@ item.Customernumber的值作为复选框ID

// this will put the value of @item.Customernumber as the checkbox id

columns.Template(@<text><input type='checkbox' id="@item.Customernumber" name="@item.CustomerNumber" value="@item.OrderNumber" /></text>).Width(50)

第二个选项:

columns.Template(@<text><input type='checkbox' id="chk_@item.Customernumber" name="@item.CustomerNumber" value="@item.OrderNumber" /></text>).Width(50)

以上内容将显示为

<input type="checkbox" id="chk_@item.Customernumber" value=... /> 

推荐答案

chk_@item.OrderNumber将不起作用,因为剃刀将其视为电子邮件,您需要这样做:chk_@(item.OrderNumber)

chk_@item.OrderNumber will not work because razor thinks of it as of an e-mail, you need to do it like this instead: chk_@(item.OrderNumber)

这篇关于如何使用Razor ASp.NET MVC连接HTML元素的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆