<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ASP.Net | DXSdata</title>
	<atom:link href="https://www.dxsdata.com/category/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dxsdata.com</link>
	<description>Software &#124; Network &#124; Administration</description>
	<lastBuildDate>Sat, 30 Sep 2023 13:16:22 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://www.dxsdata.com/wp-content/uploads/2023/08/cropped-logo-32x32.jpg</url>
	<title>ASP.Net | DXSdata</title>
	<link>https://www.dxsdata.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Solving Visual Studio 2022 slow, lagging IntelliSense</title>
		<link>https://www.dxsdata.com/2023/09/solving-visual-studio-2022-slow-lagging-intellisense/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 30 Sep 2023 12:44:35 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[Microsoft Visual Studio]]></category>
		<category><![CDATA[slow]]></category>
		<guid isPermaLink="false">https://www.dxsdata.com/?p=2216</guid>

					<description><![CDATA[Problem MS Visual Studio 2022 (currently v17.4), e.g. within a simple C# .NET console app, becomes nearly unresponsive, taking multiple seconds while typing a few characters into the editor. Solution/Workaround This should improve the editor&#8217;s AutoComplete feature a lot. If not, have a look at the references, there are a few additional option tweaks which [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Problem</h2>



<p>MS Visual Studio 2022 (currently v17.4), e.g. within a simple C# .NET console app, becomes nearly unresponsive, taking multiple seconds while typing a few characters into the editor.</p>



<p></p>



<h2 class="wp-block-heading">Solution/Workaround</h2>



<ol class="wp-block-list">
<li>Watch the current background tasks VS is running at the moment (bottom left), and make sure every task finishes within a few seconds.
<ul class="wp-block-list">
<li>If you experience e.g. a very long indexing of project files, this could be suspicious.</li>
</ul>
</li>



<li>Reset VS settings to default:
<ul class="wp-block-list">
<li>devenv /ResetSettings</li>



<li>devenv /ResetUserData</li>
</ul>
</li>



<li>Delete .vs subfolder of your project</li>



<li>Disable project cache:
<ul class="wp-block-list">
<li>Tools -&gt; Options -&gt; Environment -&gt; Preview Features -&gt; Use the project cache &#8230;</li>
</ul>
</li>
</ol>



<p>This should improve the editor&#8217;s AutoComplete feature a lot.</p>



<p>If not, have a look at the references, there are a few additional option tweaks which might be helpful.</p>



<p></p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="741" height="434" src="https://www.dxsdata.com/wp-content/uploads/2023/09/image.png" alt="" class="wp-image-2219" srcset="https://www.dxsdata.com/wp-content/uploads/2023/09/image.png 741w, https://www.dxsdata.com/wp-content/uploads/2023/09/image-480x281.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 741px, 100vw" /><figcaption class="wp-element-caption">(German Screenshot)</figcaption></figure>



<p></p>



<h2 class="wp-block-heading">References</h2>



<p><a href="https://stackoverflow.com/questions/72237599/how-to-disable-that-new-filecontentindex-folder-and-vsidx-files-in-vs-2022">https://stackoverflow.com/questions/72237599/how-to-disable-that-new-filecontentindex-folder-and-vsidx-files-in-vs-2022</a></p>



<p><a href="https://superuser.com/questions/1663409/how-to-fully-reset-all-visual-studio-settings-to-factory-defaults">https://superuser.com/questions/1663409/how-to-fully-reset-all-visual-studio-settings-to-factory-defaults</a></p>



<p><a href="https://stackoverflow.com/questions/73787513/what-is-vsidx-in-visual-studio-and-why-is-it-autogenerated">https://stackoverflow.com/questions/73787513/what-is-vsidx-in-visual-studio-and-why-is-it-autogenerated</a></p>



<p><a href="https://www.asdfreddit.com/r/VisualStudio/comments/zm252q/vs_2022_very_laggy_and_slow/">https://www.reddit.com/r/VisualStudio/comments/zm252q/vs_2022_very_laggy_and_slow/</a></p>



<p></p>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[:de]IIS 502.5 Process Failure Fehler beheben (ASP.NET Core)[:en]Solving IIS 502.5 Process Failure Error (ASP.NET Core)[:]</title>
		<link>https://www.dxsdata.com/2017/03/solving-iis-502-5-process-failure-error-asp-net-core/</link>
					<comments>https://www.dxsdata.com/2017/03/solving-iis-502-5-process-failure-error-asp-net-core/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 14 Mar 2017 17:35:39 +0000</pubDate>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1670</guid>

					<description><![CDATA[[:en] Scenario You try to publish your ASP.NET Core site to another Windows server running IIS. Error messages: Event 1000 / IIS AspNetCore Module: Application &#8216;MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE&#8217; with physical root &#8216;C:\inetpub\wwwroot\&#8217; failed to start process with commandline &#8216;&#8221;dotnet&#8221; .\yourproject.dll&#8217;, ErrorCode = &#8216;0x80004005 : 80008083. Event 1004/ IIS AspNetCore Module: Warning: Could not create stdoutLogFile [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]</p>
<h3>Scenario</h3>
<p>You try to publish your ASP.NET Core site to another Windows server running IIS.</p>
<p>Error messages:</p>
<blockquote><p>Event 1000 / IIS AspNetCore Module: Application &#8216;MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE&#8217; with physical root &#8216;C:\inetpub\wwwroot\&#8217; failed to start process with commandline &#8216;&#8221;dotnet&#8221; .\yourproject.dll&#8217;, ErrorCode = &#8216;0x80004005 : 80008083.</p>
<p>Event 1004/ IIS AspNetCore Module: Warning: Could not create stdoutLogFile \\?\C:\inetpub\wwwroot\logs\stdout_4460_201731417238.log, ErrorCode = -2147024893.</p></blockquote>
<h3>Solution</h3>
<p>To get a better error description, first correct the 1004 error, i.e. create a directory C:\inetpub\wwwroot\logs and set write permissions.</p>
<p>Afterwards, reload the site and open the logfile there. In my case, it showed this error:</p>
<blockquote><p>The specified framework &#8216;Microsoft.NETCore.App&#8217;, version &#8216;1.1.1&#8217; was not found.</p>
<p>&#8211; Check application dependencies and target a framework version installed at:</p>
<p>C:\Program Files\dotnet\shared\Microsoft.NETCore.App</p>
<p>&#8211; The following versions are installed:</p>
<p>1.0.3</p>
<p>1.1.0</p>
<p>&#8211; Alternatively, install the framework version &#8216;1.1.1&#8217;.</p></blockquote>
<p>In fact, local Visual Studio 2017 RC had been upgraded to 2017 RTM and the framework version of the project was also upgraded.</p>
<p>So basically, before you deploy/publish your project make sure your remote server runs exactly the same version of &#8220;.NET Core Windows Server Hosting&#8221;.</p>
<p>You get the latest packages <a href="https://www.microsoft.com/net/download/core#/runtime">here</a>.</p>
<p>E.g. if your remote IIS server was already configured before you upgraded anything, simply uninstall the previous .NET Core Runtime(s) via Programs &amp; Features, then install the latest .NET Core Runtime x.x.x, to be exact the &#8220;Windows Server Hosting (x64 &amp; x86)&#8221; package.[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2017/03/solving-iis-502-5-process-failure-error-asp-net-core/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[:de]ASP.NET Core: User-ID erhalten[:en]ASP.NET Core: Get User ID[:]</title>
		<link>https://www.dxsdata.com/2017/03/asp-net-core-get-user-id/</link>
					<comments>https://www.dxsdata.com/2017/03/asp-net-core-get-user-id/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 08 Mar 2017 14:46:49 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1651</guid>

					<description><![CDATA[[:en]Using Microsoft.AspNetCore.Identity, you might miss a method like GetUserId() which was available for previous .NET frameworks by default. As a workaround, use this extension method: using System.Security.Claims; namespace myproject.Common { public static class ExtensionMethods { /// &#60;summary&#62; /// User ID /// &#60;/summary&#62; /// &#60;param name="user"&#62;&#60;/param&#62; /// &#60;returns&#62;&#60;/returns&#62; public static string getUserId(this ClaimsPrincipal user) { if [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]Using Microsoft.AspNetCore.Identity, you might miss a method like GetUserId() which was available for previous .NET frameworks by default.</p>
<p>As a workaround, use this extension method:</p>
<pre class="lang:c# decode:true">using System.Security.Claims;

namespace myproject.Common
{
    public static class ExtensionMethods
    {
        /// &lt;summary&gt;
        /// User ID
        /// &lt;/summary&gt;
        /// &lt;param name="user"&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static string getUserId(this ClaimsPrincipal user)
        {
            if (!user.Identity.IsAuthenticated)
                return null;

            ClaimsPrincipal currentUser = user;
            return currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
        }

    }
}
</pre>
<p>Usage:</p>
<pre class="lang:sh decode:true">using myproject.Common;

...

var userId = User.getUserId();</pre>
<p>&nbsp;[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2017/03/asp-net-core-get-user-id/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>ASP.NET EditorTemplates</title>
		<link>https://www.dxsdata.com/2017/02/asp-net-editortemplates/</link>
					<comments>https://www.dxsdata.com/2017/02/asp-net-editortemplates/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 11 Feb 2017 16:31:21 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1446</guid>

					<description><![CDATA[[:en]ASP.NET offers a good way to keep your code clean of redundant data, e.g. Bootstrap classes you would have to assign to every visible HTML element again and again. As a .NET Core MVC sample for single elements, you would write code like @Html.TextBoxFor(m =&#62; m.StartTime, new { @class = "form-control", @type = "datetime" }) Or, if [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]ASP.NET offers a good way to keep your code clean of redundant data, e.g. Bootstrap classes you would have to assign to every visible HTML element again and again.</p>
<p>As a .NET Core MVC sample for single elements, you would write code like</p>
<pre class="lang:asp decode:true">@Html.TextBoxFor(m =&gt; m.StartTime, new { @class = "form-control", @type = "datetime"  })</pre>
<p>Or, if you use tools like the <a href="https://eonasdan.github.io/bootstrap-datetimepicker/">bootstrap-datetimepicker</a> for a comfortable date and time input, there would be even more DIVs:</p>
<pre class="lang:asp decode:true">&lt;div class='input-group date' id='datetimepickerStarttime'&gt;
    
    @Html.TextBoxFor(m =&gt; m.StartTime, new { @class = "form-control", @type = "datetime"  })

    &lt;span class="input-group-addon"&gt;
        &lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
    &lt;/span&gt;
&lt;/div&gt;</pre>
<h2>How to use templates</h2>
<p>You can specify EditorTemplates for certain types or models. The same behavior works e.g. for DisplayTemplates (DisplayFor()). I will explain how to create an EditorTemplate for type DateTime.</p>
<p>First, create a folder and an empty file: \Views\Shared\EditorTemplates\DateTime.cshtml</p>
<p>Paste this code into it:</p>
<pre class="lang:asp decode:true ">&lt;div class='input-group date' id='@("datetimepicker"+ViewData.TemplateInfo.HtmlFieldPrefix)'&gt;
    
    @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "form-control", type = "datetime" })

    &lt;span class="input-group-addon"&gt;
        &lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
    &lt;/span&gt;
&lt;/div&gt;
</pre>
<p>Afterwards, you can simply write</p>
<pre class="lang:asp decode:true ">@Html.EditorFor(m =&gt; m.StartTime)</pre>
<p>into your main cshtml file to get the full template loaded:</p>
<p><a href="https://www.dxsdata.com/wp-content/uploads/2017/02/bootstrap-datetimepicker-editortemplates.png" rel="attachment wp-att-1447"><img loading="lazy" decoding="async" class="alignnone wp-image-1447 size-full" src="https://www.dxsdata.com/wp-content/uploads/2017/02/bootstrap-datetimepicker-editortemplates.png" width="327" height="105" /></a></p>
<p>For JavaScript/jQuery access, use the value we created in the first line of the template, datetimepicker[yourModelPropertyName], in this case &#8220;datetimepickerStartTime&#8221;.</p>
<p>Example:</p>
<pre class="lang:java decode:true ">$('#datetimepickerStartTime').datetimepicker();</pre>
<p>&nbsp;</p>
<p>&nbsp;[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2017/02/asp-net-editortemplates/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[:de]ASP.Net MVC Razor: Ersatz für DropDownListFor() zum Ergänzen von Attributen bei Optionen[:en]ASP.Net MVC Razor: Replacement for DropDownListFor() for adding attributes to options[:]</title>
		<link>https://www.dxsdata.com/2016/07/asp-net-mvc-razor-replacement-for-dropdownlistfor-for-adding-attributes-to-options/</link>
					<comments>https://www.dxsdata.com/2016/07/asp-net-mvc-razor-replacement-for-dropdownlistfor-for-adding-attributes-to-options/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 12 Jul 2016 15:08:21 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# .Net]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1180</guid>

					<description><![CDATA[[:en]By default, @Html.DropDownListFor() is a convenient Razor helper to create a &#60;select&#62; tag containing &#60;option&#62; tags. But it is not possible to add custom attributes like &#8220;data-meow-xx=xxxx&#8221; to the option tags. One solution is to create the &#60;select&#62; tag yourself: &#60;select name="@Html.NameFor(m =&#62; m.mycol)" id="@Html.IdFor(m =&#62; m.mycol)" class="form-control"&#62; @foreach (var item in ViewBag.myoptions) { &#60;option [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]By default, @Html.DropDownListFor() is a convenient Razor helper to create a &lt;select&gt; tag containing &lt;option&gt; tags. But it is not possible to add custom attributes like &#8220;data-meow-xx=xxxx&#8221; to the option tags.</p>
<p>One solution is to create the &lt;select&gt; tag yourself:</p>
<pre class="lang:c# decode:true">&lt;select name="@Html.NameFor(m =&gt; m.mycol)" id="@Html.IdFor(m =&gt; m.mycol)" class="form-control"&gt;
                                                  
    @foreach (var item in ViewBag.myoptions)
    {
        &lt;option value="@item.name" data-src-mycustomstuff="myStuff/@item.name"
                       selected="@(Model != null &amp;&amp; item.name == Model.mycol)"&gt;
            @item.name_friendly
        &lt;/option&gt;
    }
&lt;/select&gt;</pre>
<p><a href="http://stackoverflow.com/questions/17665426/selectlistitem-with-data-attributes">Reference</a></p>
<p>&nbsp;[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/07/asp-net-mvc-razor-replacement-for-dropdownlistfor-for-adding-attributes-to-options/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[:de]ASP.Net MVC, Entity Framework: Benutzerfreundliche Model-Spaltenbezeichnungen (Metadaten)[:en]ASP.Net MVC, Entity Framework: Show user friendly model column names (Metadata)[:]</title>
		<link>https://www.dxsdata.com/2016/07/asp-net-mvc-entity-framework-show-user-friendly-model-column-names-metadata/</link>
					<comments>https://www.dxsdata.com/2016/07/asp-net-mvc-entity-framework-show-user-friendly-model-column-names-metadata/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 12 Jul 2016 07:04:28 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1172</guid>

					<description><![CDATA[[:en]Databases like MySQL do not allow any special characters in table column names, so most developers use camelcase or underscores. To make it readable for the end user in your software, you often have to manually type a friendly description. As there is no way to set a &#8220;friendly name&#8221; value in the DB table [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]Databases like MySQL do not allow any special characters in table column names, so most developers use camelcase or underscores. To make it readable for the end user in your software, you often have to manually type a friendly description.</p>
<p>As there is no way to set a &#8220;friendly name&#8221; value in the DB table structure directly, you might think of putting some additional data into the .Net database entity  model. This is not always a good idea, because data could get lost when you update your model structure from DB.</p>
<p>So the most useful way I found so far in ASP.Net is to use a combination of System.ComponentModel.DataAnnotations and Model Metadata.</p>
<p><strong>Example</strong></p>
<p>You have a table mytable in your model mymodel, which contains a column mycolumn. The friendly name for mycolumn should be &#8220;My Column&#8221;.</p>
<p>In your Models folder (Visual Studio Solution Explorer), create 2 class files called MetaData.cs and PartialClasses.cs.</p>
<p>&nbsp;</p>
<pre title="MetaData.cs" class="lang:c# decode:true ">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace myproject.Models
{
    public class MetaData
    {
        public class mytableMetaData
        {
            [Display(Name = "My Column")]
            public object mycolumn;
            

        }
    }
}

</pre>
<pre title="PartialClasses.cs" class="lang:c# decode:true ">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace myproject.Models
{    
    [MetadataType(typeof(MetaData.mytableMetaData))]
    public partial class mytable
    {
    }
}</pre>
<p>In your .cshtml file, use:</p>
<pre class="lang:c# decode:true">@Html.DisplayNameFor(m =&gt; m.mycolumn)</pre>
<p>You should now see the friendly column name &#8220;My Column&#8221; in your browser.</p>
<p>E.g. &#8220;@Html.ValidationSummary()&#8221; now also uses the display name from Metadata.</p>
<p>If you refresh your model structure later, these two classes are not affected.</p>
<p><a href="http://www.asp.net/mvc/overview/getting-started/database-first-development/enhancing-data-validation">Reference</a>[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/07/asp-net-mvc-entity-framework-show-user-friendly-model-column-names-metadata/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ASP.Net / MVC / Entity Framework: Nullable DropDownList</title>
		<link>https://www.dxsdata.com/2016/06/asp-net-mvc-entity-framework-nullable-dropdownlist/</link>
					<comments>https://www.dxsdata.com/2016/06/asp-net-mvc-entity-framework-nullable-dropdownlist/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 13 Jun 2016 13:37:30 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# .Net]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1142</guid>

					<description><![CDATA[[:en]Scenario In your SQL database table, you have e.g. a foreign key relation &#8211; a nullable column of one table references another table which contains the items for your DropDownList (HTML Select). But by default, Html.DropDownListFor() does not have an option for the user to choose the NULL value. Solution Add a NULL option to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]<strong>Scenario</strong></p>
<p>In your SQL database table, you have e.g. a foreign key relation &#8211; a nullable column of one table references another table which contains the items for your DropDownList (HTML Select).</p>
<p>But by default, Html.DropDownListFor() does not have an option for the user to choose the NULL value.</p>
<p><strong>Solution</strong></p>
<p>Add a NULL option to your list before you call DropDownListFor().</p>
<p>In your View:</p>
<pre class="lang:asp decode:true">&lt;div class="dropdown"&gt;
    Example
    @{
          var list = new SelectList(ViewBag.list, "name", "name_friendly", "(none)").ToList();
          list.Insert(0, new SelectListItem() { Value = null, Text = "(none)" });
     }
     @Html.DropDownListFor(yourFkTable =&gt; yourFkTable.chosenItem, list)
&lt;/div&gt;</pre>
<p><strong>UPDATE</strong> 2016-07-16:</p>
<p>The above solution might case controller validation errors.</p>
<p>But there is a much easier way.</p>
<pre class="lang:sh decode:true">&lt;div class="dropdown"&gt;
    Example
        @Html.DropDownListFor(yourFkTable =&gt; yourFkTable.chosenItem, list, "(none)")
&lt;/div&gt;</pre>
<p>If the third parameter is given, &#8220;(none)&#8221; will be converted into &#8220;<em>&lt;option value=&#8221;&#8221;&gt;</em>&#8220;, which is accepted by your controller.</p>
<p>Also make sure your SQL column value allows null values.</p>
<p><a href="http://stackoverflow.com/questions/21237129/asp-net-mvc-5-dropdownlist-nullable-int-default-option-not-null">Reference</a>[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/06/asp-net-mvc-entity-framework-nullable-dropdownlist/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[:en]ASP.Net, MVC, Razor C#: Display images from database (BLOB)[:]</title>
		<link>https://www.dxsdata.com/2016/06/asp-net-mvc-razor-c-display-images-from-database-blob/</link>
					<comments>https://www.dxsdata.com/2016/06/asp-net-mvc-razor-c-display-images-from-database-blob/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 01 Jun 2016 17:12:13 +0000</pubDate>
				<category><![CDATA[ASP.Net]]></category>
		<guid isPermaLink="false">http://www.dxsdata.com/?p=1135</guid>

					<description><![CDATA[[:en]Scenario You have an SQL datatable which contains a BLOB column to save images direcly in your DB as binary and want to show the images on your website. Solution Create your EntityFramework and Controller with the common wizards and methods. Because you cannot directly give a Byte Array to your browser, you have to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[:en]<strong>Scenario</strong></p>
<p>You have an SQL datatable which contains a BLOB column to save images direcly in your DB as binary and want to show the images on your website.</p>
<p><strong>Solution</strong></p>
<p>Create your EntityFramework and Controller with the common wizards and methods.</p>
<p>Because you cannot directly give a Byte Array to your browser, you have to edit your .cshtml file to insert the images directly into your HTML code as Base64 strings:</p>
<pre class="lang:xhtml decode:true">@foreach (var item in Model)
{
     @{
       String img64 = Convert.ToBase64String(item.image);
       String img64Url = string.Format("data:image/"+item.imagetype+";base64,{0}", img64); //imagetype can be e.g. gif, jpeg, png etc.
      }
      &lt;img src="@img64Url"/&gt;
}</pre>
<hr />
<p>A method which offers the images via Controller would be to add ActionResult methods (and/or parameters) for your images.</p>
<p>In your Controller:</p>
<pre class="lang:c# decode:true">public ActionResult GetImage()
{
    byte[] imageByteData = yourmodel.yourtable...yourImage;
    return File(imageByteData, "image/png"); 
}

//UPDATE 2016-06-07: 
//Some Browsers like IE do not seem to accept the ContentType parameter of File() and change it to GIF, which may result in lower image quality!
//Better use this code:
public ActionResult GetImage()
{
   System.IO.MemoryStream ms = new System.IO.MemoryStream();
   yourImage.Save(ms, resultImageType); //or use your Byte[] directly with Memorystream constructor
   ms.Position = 0;
   return new FileStreamResult(ms, "image/png");
}</pre>
<p>Now the src attribute of the image tag should point to /Home/GetImage.</p>
<p>In your View:</p>
<pre class="lang:xhtml decode:true">&lt;img src='@Url.Action("GetImage", "Home")'/&gt;</pre>
<p>&nbsp;</p>
<p><a href="http://www.binaryintellect.net/articles/e6d71127-1f12-4555-879b-6a859947eafa.aspx">Reference</a>[:]</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dxsdata.com/2016/06/asp-net-mvc-razor-c-display-images-from-database-blob/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
