enter image description here

As you can see here with the latest service pack from Visual Studio 2015, no more highlights and syntax colors for Razor code

Could somebody please provide an example of how to combine 15 models within one view? I can't use Tuple coz Tuple only support 4 model in One View... after 5 razor syntax not support.. So I used Dictionary for List i can be done by Create view only but I can't save by each model...

in Controller Create View

    public ActionResult Create()
             var model = new Dictionary<string, Model>()
                { "table1", new validation.table1() },
                { "table2", new validation.table2() },
                { "table3", new validation.table3() },
                { "table4", new validation.table4()},
                { "table5", new validation.table5()},
                { "table6", new validation.table6()},
                { "table7", new validation.table7()},
                { "table8", new validation.table8()},
                { "table9", new validation.table9()},
                { "table10", new validation.table10()},
                { "table11", new validation.table11()},
                { "table12", new validation.table12()},
                { "table13", new validation.table13()},
                { "table14", new validation.table14() },
                { "table15", new validation.table15()}
           return View(model);
        catch (Exception ex)
            throw ex;

With the new ASP.NET 5 doing away with web.config, and thus the ConfigurationManagement namespace, I was trying to figure out how to read the connection string from my data access layer project in my MVC application.

Researching this issue, everything I've found says to just read the config value from the project.json configuration file in the Startup.cs file like this:

var configuration = new Configuration();


var connString = configuration.Get("Data:DefaultConnection:ConnectionString");

But I don't want my web project having anything to do with the data access. So, how does my data access layer project retrieve the connection string in this setup?

My problem is i want to create a category page , show my post that related to a category ..

this is my controller :

 // GET: Category/{id}
    public ViewResult Index(int id)
        var result = db.Books.Where(b => b.Category_id == id).ToList();
        return View(result);

it's work well in browser with no problem , but the link looks like :


and it's show all the post related to category id 1 , but i want the link to looks like this : http://localhost:49119/Category/1

is that possible and how to do this ??

also this is how's the view looks : views->Category->index.cshtml

I currently have a page with a drop-down list (containing a list of users) and a button which submits the selection.

When a username is selected in the ddl, I want to load the information about that user to be displayed to the page.

I'm unsure of the best way to do this in asp.net MVC. I currently have a post request happening when the button is pressed, but am unsure how to add more information to the same page instead of redirecting to another page on click.

Created a asp.net 5 project with another team member and works on everyone's computer but mine. I get "Failed to load resource: the server responded with a status of 500 (Internal Server Error and the web page is blank.Internal Server Error

I thought maybe I was missing a .net version but when downloading .NET Framework 4.6 it says ".NET Framework 4.6 or a later update is already installed on this computer." If someone could point me in the right direction it would be a lot of help! Thanks!

This question already has an answer here:

I got the following code in my asp.net mvc VIEW.

<div class="row">
  <div class="col-sm-12">
    <span id="errorId" class="glyphicon glyphicon-remove" style="color: #FF0004;"></span> @Model.ErrorMessage

The @Model.ErrorMessage may contain contain multiple strings but when the View is rendered, I don't see the line break. I tried adding <br /> and \r\n but its all rendered on 1 line.

Here is a sample of the returning error message:

The first field is required.\r\nThe second field is required.\r\nThe third field is required.\r\n

I replaced the \r\n with <br> line tag but it still does not work.

how can I break the string up into separate lines? Thanks.

Using asp.net when the URL is empty (http://localhost:123) the logout link does nothing.

My Site.Master uses LoginStatus for Login/Logout.

<asp:LoginStatus runat="server" LogoutAction="Redirect"  LogoutText="Log off" LogoutPageUrl="/Account/Logout" OnLoggingOut="Unnamed_LoggingOut"/>

Navigating to an URL such as http://localhost:123/Home and logout functions properly going into Unnamed_LoggingOut in Site.Master.cs.

The method Unnamed_LoggingOut or /Account/Logout-Page_Load are not called on an empty URL.

Any ideas?

So I am currently working on an application that uses WebAPI and AngularJS to search for some data from a SQL table and display it on a webpage for the user to select multiple individual rows of data. I am inserting the selected rows into a separate JSON array (availableclients) that I would like to insert into a separate SQL table. What is the best method for me to take my array of JSON data and insert it into a different SQL table. I will attach the code I am currently using to get the data.


var app = angular.module('myApp', []);

app.controller("myController", function ($scope, $http) {

  function getCert(myid) {
    $http.get('api/Cert/Get/', { params: { id : myid } })
      .success(function (data) {
        $scope.selectedclients = data;

  $scope.searchClick = function() {

  $scope.moveItem = function (item, from, to) {
    var idx = from.indexOf(item);
    if (idx != -1) {
      from.splice(idx, 1);

  $scope.availableclients = [];


<html data-ng-app="myApp">
  <body data-ng-controller ="myController">    

My_ID: <input type="text" ng-model="my_id" />
    <input type="submit" value="Search" ng-click="searchClick()" />

    <select size="10" multiple ng-model="selected" ng-options="i.unit_id for i in selectedclients" style="width: 400px"></select>
    <div class="btn-group">
      <button title="Remove From List" class="btn btn-default" ng-click="moveItem(available[0], availableclients,selectedclients)"><i class="glyphicon glyphicon-chevron-left"></i></button>
      <button title="Add To List" class="btn btn-default" ng-click="moveItem(selected[0], selectedclients,availableclients)"><i class="glyphicon glyphicon-chevron-right"></i></button>
    <select size="10" multiple ng-model="available" ng-options="i.unit_id for i in availableclients" style="width: 400px"></select>

The code I have is working fine I am just at a loss for how to take my availableclients JSON array and insert it into my SQL table. This is probably really easy to do but all my searches are coming up blank on what I am looking for exactly. Any help is appreciated. Thanks!

I have Resharper 10 installed in Visual Studio 2013. My solution contains a view .cshtml file that displays a date using Razor. However, Resharper displays the DateTime with a red warning highlight, and prompts me to import the System.DateTime namespace - please see the linked image:

DateTime error

The strange thing is that when my colleagues open the solution on their machines - exactly the same code, using the same version of VS2013 with the same Resharper version - there is no Resharper error.

The namespaces section of the Web.config file in the Views folder looks like this:

    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />

If I add the System namespace, ie:

<add namespace="System" />

.. then the issue goes away. But - this doesn't explain why the issue only appears on one machine, and not on others.

I've tried cleaning the solution, suspending & resuming Resharper, clearing the Resharper cache, deleting the .suo file for the project, etc.

This seems so simple, but I really cannot figure out why R# would warn me on one machine, but not on others, when the code and environment seem to be identical.

Any suggestions? Could Resharper's warning be a result of some wider configuration issue on my machine?

I have multiple foreach loops over a one item List field in my Model class (without changes to the Model between them). The first loop works and finishes successfully but in the second loop I get a KeyNotFoundException (after the first iteration of the loop).

The code looks similar to this:

    @foreach(var item in Model.Listfield) // this loop works
        <option value="@item.ID">@item.Name</option>
<div>other stuff</div>
@foreach(var item in Model.Listfield) // exception here
    // all code in the loop is commented out, but still exception

The exception does occur every time the page is opened with one model, but never when opened with another model. Both models are different in some fields but have the same list field for the foreach loop. So the exception is not generally reproducable but always for the one model for me.

What could cause this strange behavior?

I am wondering if anyone could help with the issue that I am having. I have a form in which, I am putting ReCaptcha v2. No matter what I try I can not get ReCaptcha to be in the correct alignment with the rest of the form which would be directly underneath the text boxes with writing to the left. I would be grateful if someone could help me solve this issuse

The Form

@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))

@Html.ValidationSummary("", new { @class = "text-danger" })

<div class="form-group">
    @Html.LabelFor(m => m.FirstName, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control" })

<div class="form-group">
    @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
<div class="form-group">
    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
<div class="form-group">
    @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })

    div.g-recaptcha {

        left: 0px;
        width: 304px;

<div class="form-group">
  Are You Human
    <div class="col-md-10">
        <div align="center" class="g-recaptcha" data-sitekey="sitekey"></div>

<div class="form-group">
    <div class="col-md-offset-2 col-md-10">
        <input type="submit" class="btn btn-default" value="Register" />

An image of what is happening.

enter image description here

Richards Approach

enter image description here

This is my simple username and password login which has the ability to redirect the user to a different 'members area' page.

However I get a:

BC32045: 'System.Collections.IEnumerable' has no type parameters and so cannot have type arguments

And I have no idea why.

Can anyone help?

Thanks, David.

Public Class MyPage
Inherits Page
Private Structure Cred
    Public Username As String
    Public Password As String
    Public RedirectUrl As String
    Public Sub New(un As String, pw As String, Optional ru As String = "/admin/default.aspx")
        Username = un
        Password = pw
        RedirectUrl = ru
    End Sub
End Structure

Private ReadOnly _credentials As IEnumerable(Of Cred) = New () {New Cred("userone", "passwordone"), New Cred("usertwo", "passwordtwo"), New Cred("userthree", "passwordthree", "/admin/custom.aspx")}

Public Sub Page_Load(sender As Object, e As EventArgs)
    Dim user = _credentials.SingleOrDefault(Function(x) x.Username = UserName.Text AndAlso x.Password = Password.Text)
    If user IsNot Nothing Then
        Session("Admin") = True
        Session("Admin") = False
        LtlLogin.Text = "<p>Sorry, you have provided incorrect login details.</p>"
    End If
End Sub
End Class

I created an ASP.Net webforms project, and after doing all the backend stuff, I now want to work on the design. I want to use Google Material Design Lite. The project currently has all the Bootstrap styles that it puts in when I created the project and I want to remove all of that. I removed all of the stylesheet files I could find, and yet the appearance of the site remains the same. Where is it getting the stylesheet information from if not from *.css files and how do I get rid of it?

I'm having a controller which shall create an object through the usage of data given by a form. The problem is, that I need to get the object by its foreign key and I actually don't know what I should search for

I tried to get the object like this, but I'm getting the error that I cannot implicitly convert System.Linq.IQueryable to Model.Object:

Object object = db.Objects.Where(o => o.ProcessId == postData.ProcessId);

Is there an other, maybe more elegant way to get the object by its foreign key?

i am creating a webform which basically asks the user to select files so that they can be uploaded to onedrive folder. Also, when the user clicks to add an extra file, an extra tag: () is added to the html and finally when the upload button is clicked, all these files are parsed in the codebehind and uploaded. Though i have been succesful in uploading one file, when adding more input tags, it gives me an error saying cannot parse FileUpload' + filecount. When i checked my code, i found out that whenever i write runat="server", the same gets reflected in my designer.cs, how can i solve this problem

The html code is as follows:

<asp:FileUpload ID='FileUpload1' runat='server' style="margin-left: 2px" Width="225px" />

<div id="asptags"> 
<input type="button" id="add" value="+" />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" />

        var filecount = 1;
        $('#add').click(function () {

            filecount = filecount + 1;

            var x = '<asp:FileUpload class="FileUpload'+filecount+'" runat="server" />';

            document.getElementById("asptags").innerHTML += x;


So i write project and I have next architecture:

API(s) AdminAPI (WebAPI) ClientAPI(webAPI)

I did separate apis for better security - for nobody dont can see request to admin api

BL,DAL, etc. - not important in this question

WebSites(2) Admin website Client website

No in client website I have 2 big parts and actually it's 2 angular apps

1) COntrol panel for user - like seller 2) Just user.

So seller do simple registration and I create User class instace - and all works good

But for just user - i want give option to login ONLY with Facebook

I did like in Facebook tutorial:

  (function (d, s, id) {
                    var js, fjs = d.getElementsByTagName(s)[0];
                    if (d.getElementById(id)) return;
                    js = d.createElement(s); js.id = id;
                    js.src = "//connect.facebook.net/en_US/sdk.js";
                    fjs.parentNode.insertBefore(js, fjs);
                }(document, 'script', 'facebook-jssdk'));

            appId: 'HERE IS MY APP ID',
            cookie: true,  // enable cookies to allow the server to access
            // the session
            xfbml: true,  // parse social plugins on this page
            version: 'v2.2' // use version 2.2

FB.getLoginStatus(function (response) {

            function statusChangeCallback(response) {
                // The response object is returned with a status field that lets the
                // app know the current login status of the person.
                // Full docs on the response object can be found in the documentation
                // for FB.getLoginStatus().
                if (response.status === 'connected') {
                    // Logged into your app and Facebook.
                } else if (response.status === 'not_authorized') {
                    // The person is logged into Facebook, but not your app.
                    document.getElementById('status').innerHTML = 'Please log ' +
                      'into this app.';
                } else {
                    // The person is not logged into Facebook, so we're not sure if
                    // they are logged into this app or not.
                    document.getElementById('status').innerHTML = 'Please log ' +
                      'into Facebook.';

            // This function is called when someone finishes with the Login
            // Button.  See the onlogin handler attached to it in the sample
            // code below.
            function checkLoginState() {
                FB.getLoginStatus(function (response) {

            function testAPI() {
                console.log('Welcome!  Fetching your information.... ');
                FB.api('/me', function (response) {
                    console.log('Successful login for: ' + response.name);
                    document.getElementById('status').innerHTML =
                      'Thanks for logging in, ' + response.name + '!';
              function (response) {
                  if (response && !response.error) {
            vm.Logout = function () {
                FB.logout(function (response) {

            vm.Login = function () {
                FB.login(function (response) {
                    if (response.authResponse) {
                        console.log('Welcome!  Fetching your information.... ');
                        FB.api('/me', function (response) {
                            FB.getLoginStatus(function (response2) {
                            console.log('Good to see you, ' + response.name + '.');
                    } else {
                        console.log('User cancelled login or did not fully authorize.');
                }, {

                    scope: 'publish_actions,user_posts',
                    return_scopes: true

All this code work fine. But I have next question.

User did login. I got access token and exp. time.

What I need to save in database, I mean - I want to give to user (after login) Option like save to watch list, like, following for other user or something

so What I need to save in database for understand each time which user now ? Because access token is dynamic, right?

So guys I'm confused - I dont know how do it)

Thank you and sorry for my English grammar

P.S - Dont know if its important in this case I have My Oqth provider - because I use couchbase databse - and I write my own IdentityProvider


I am working with my local website which displays local contents in local language.


Unfortunately my local language not supported by the Google Ads as per:

enter image description here

So one way I thought was to convert all text/string into image and display images instead.(Server Side)


I am using c# method to convert text to image. I dont understand its implementation for multi-line text?

Or is there a better way to support languages that ad sense doesn't support without images?

C# Code

            string text = str.Trim();
            Bitmap bitmap = new Bitmap(1, 1);
            Font font = new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Pixel);
            Graphics graphics = Graphics.FromImage(bitmap);
            int width = (int)graphics.MeasureString(text, font).Width;
            int height = (int)graphics.MeasureString(text, font).Height;
            bitmap = new Bitmap(bitmap, new Size(width, height));
            graphics = Graphics.FromImage(bitmap);
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0);
            string fileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".jpg";
            bitmap.Save(Server.MapPath("~/App_Images/") +"11"+fileName, ImageFormat.Jpeg);
            //imgText.ImageUrl = "~/images/" + fileName;
            //imgText.Visible = true;
            return "~/App_Images/My_Converted.jpg";

If someone have any idea about this type of problem or any refrence/link, please do help. Thanks for your time.

The project templates that are available in Visual Studio 2015 for asp.net all depend on RC1.

Some digging led me to the list of changes between RC1 and RC2, which showed me that there's been some renaming (WebApplication is now WebHost), but the number of other breaking changes that are there suggest that, since I've only just started, it'd be easier to start over with an updated project template.

Except that I can't find one.

Are updated project templates available? Where do I find them?

I'm writing a tool to help users make use of my ASMX webservice, and I'd like to show the users sample SOAP requests for various methods.

If you have an asmx webservice ASP.NET automatically generates a page for each method which displays a sample SOAP request and response. You can see an example here.

Clearly, a System.Web.Services.WebService generates this sample somewhere, but I don't know where. How can I get hold of the soap samples programmatically so that I can use them elsewhere?

I have an aspx that cotains this code:

<asp:FormView runat="server"

                <legend><%#: Item.Bezeichnung %> (<%#: Item.Veranstaltungsnummer %>)</legend>
                <table class="content-table">
                        <td class="dark-table"><span style="font-weight:bold;">Beschreibung:</span></td>
                        <td class="light-table"><%#: Item.Beschreibung %></td>
                        <td class="dark-table"><span style="font-weight:bold;">Ort:</span></td>
                        <td class="light-table"><%# Item.Ort %></td>

                <legend>Neue Veranstaltung anlegen</legend>
                  <table class="content-table">
                        <td class="dark-table"><span style="font-weight:bold;">Beschreibung:</span></td>
                        <td class="light-table"><asp:TextBox runat="server" ID="insert_beschreibung" Text="<%#: BindItem.Beschreibung %>"></asp:TextBox></td>
                        <td class="dark-table"><span style="font-weight:bold;">Ort:</span></td>
                        <td class="light-table"><asp:TextBox runat="server" ID="insert_ort" Text="<%#: BindItem.Ort %>"></asp:TextBox></td>

                <legend>Veranstaltung bearbeiten "<%#: Item.Bezeichnung %>"</legend>
                  <table class="content-table">
                        <td class="dark-table"><span style="font-weight:bold;">Beschreibung:</span></td>
                        <td class="light-table"><asp:TextBox runat="server" ID="edit_beschreibung"  Text="<%# BindItem.Beschreibung %>"></asp:TextBox></td>
                        <td class="dark-table"><span style="font-weight:bold;">Ort:</span></td>
                        <td class="light-table"><asp:TextBox runat="server" ID="edit_ort" Text="<%#: BindItem.Ort %>"></asp:TextBox></td>

The data is managed by Entity Framework. In most cases, everything is working fine. But if I enter Umlaute (ÄÖÜ äöü) I run into problems. When I enter them and save, everything is fine. The Data appears correctly in the database. When I view the data, e.g. , everything is fine. But when I try to edit the data in the data gets html-encoded as ÄÖÜ and I can't save it again. I'm no expert at asp.net so I'm at a loss right now. Where is my mistake? Thanks for your help.