I am trying to shorten a text field that is sometimes too large, Is empty I
@ html.DisplayFor (modelItem = & gt; item.MainBiography)
and finally replace it with three points.
I have
update:
This is not very important, so I tried
@ html.DisplayFor (ModelItem = & gt; item.MainBiography.Substring (0,10))
and get the following error code:
System. Invalid Operation exception user Code = HResult = - 2146233079 Message = templates can only be used with Field Access, Property Access, Single-Dimension Array Index, or Single-Parameter Custom Indexer Expression It is. Source = System.Web.Mvc -
You are better than creating a separate property model In, to select main detail
and at the end to shorten it.
Like it:
// This is your property (sample) Public string mesneography {receive; Set; } // How long do you want your property? // (Advice for best practice against magic number) Private intimmigraphy lilit = 100; // You probably need it if you LabelFor () // and copy this property to "full" one [display (name = "main biography")] public string menobiography ({ Limit) Return it back.Manobiography Shuttleing (0, this.MainBiographyLimit) + "..."; And return it back. }}
will be used
@ html.DisplayFor (item => item.MainBiographyTrimmed)
Another approach would be to create a full visual model, but I think it is not greater than that.
Comments
Post a Comment