''string' does not contain a definition for 'AsInt' in .Net Core
I am trying to introduce below code in .Net core MVC 3.1 cshtml file:
<p id="DisableInfo">
Your session will expire in @(System.Configuration.ConfigurationManager.AppSettings["SessionExpNotice"].AsInt() / 6) minutes, Click Ok to remain logged in or click Cancel to log off.
If you are logged off any changes will be lost.
</p>
But when in converted to .NET Core, I'm getting this error
'string' does not contain a definition for 'AsInt' and no accessible extension method 'AsInt' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Solution 1:[1]
.AsInt() is an extension method for Microsoft.AspNet.WebPages.
Alternative, convert to int type via Convert.ToInt32().
@(Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SessionExpNotice"]) / 6)
Or else you need to implement the extension method for string.AsInt().
public static class StringExtensions
{
public static int AsInt(this string @value)
{
return Int32.TryParse(@value, out int output)
? output
: 0;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
