简体   繁体   English

在Razor View中模型属性值的空间无法正确映射ASP.NET MVC

[英]Model Property Value having Space not mapping Correctly In Razor View ASP.NET MVC

I have a property FirstName in a employee model, the value of the FirstName is bilal khan, when i fetch the data and map it to html tags it parsed incorrectly after space word is not mapping. 我在员工模型中有一个属性FirstName,FirstName的值是bilal khan,当我获取数据并将其映射到html标签后,如果不映射空间字,该标签将被错误地解析。

public Class Employee
{
    public string FirstName {get; set; }
}
//set employee FirstName="Bilal Khan"

I have strongly type view bind with employee class 我有强类型视图绑定员工类

@foreach (var item in Model)
{
    <li id=@item.ChatDialogID class="person"  data-chat-recievername=@item.RecieverDisplayName>
}

Browser output 浏览器输出

when i do inspect element above information display in the browser like 当我检查上述信息时,元素在浏览器中显示为

<li id="1" class="person active" data-chat="1" data-chat-sender="15" data-chat-reciever="20080" data-chat-recievername="bilal" khan="">

as you can see that it takes the first word and not the second one. 如您所见,它使用第一个单词而不是第二个单词。

您需要将属性值括在引号中

<li id="@item.ChatDialogID" class="person" data-chat-recievername="@item.RecieverDisplayName">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM