.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

VWD2010, MVC2, Html.ActionLink and Application[]

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :ASP.Net


This is my code:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    if (Request.IsAuthenticated) {
        <%:Application["Welcome"] %> <b><%: Page.User.Identity.Name %></b>!
        [ <%: Html.ActionLink(Application["LogOut"].ToString, "LogOff", "Account") %> ]
    else {
        [ <%: Html.ActionLink(Application["LogIn"].ToString, "LogOn", "Account") %> ]


What I want to do is pretty simple, I set appropriate values in the application array at the global.asax level and would then want to see those values be written in place of the default ones. That obviously does not happen or I wouldn't be writing here :-P


It gives out an error saying it doesn't find an correct overload for the method ActionLink(or something along these lines anyway).

Clearly, that's wrong :-P since I would expect it to display m

View Complete Post

More Related Resource Links

Tip #107 Did you know . How to improve debugging performance for MVC2 application in Visual Studio 2

VS2010 Ultimate included IntelliTrace functionality by default.  IntelliTrace captures events (e.g. exceptions), and can affect performance of debugging. The typical performance hit is about 5% in the default mode (collection can be increased to...(read more)

Conditional styles for selected Html.ActionLink


Hi, I am trying to add an item selected class to an Html.ActionLink, I am very new to MVC so its all a bit confusing.

So far i have each of my ActionLinks lookins like this

<li><%: Html.ActionLink("Home", "Index", "Home", new { @class = ViewData["current"] == "Home" ? "selected" : "" })%></li>

And in the controller i have

public ActionResult Index() {
            ViewData.Add("current", "Home");
            return View();

Can any one tell where i am going wrong because the links now fail to respond, basically it isn't checking the condition == Home and if it is then its failing because it doesn't get to the controller.

Any ideas would be appreciated


Migrating MVC1 application to MVC2

I am having a Asp.net MVC1 based application which needs to be migrated to Asp.net MVC2. I opened this application in vs2010 and it automatically migrated it to MVC2. However one of its code line is creating problem during page exceution. I have following line in Application_start funtion of Global.asax ModelBinders.Binders.DefaultBinder = new Microsoft.Web.Mvc.DataAnnotations.DataAnnotationsModelBinder(); This is because Microsoft.Web.MVC.DataAnnotations dll is missing in MVC2. I tried to skip this error by commenting this code but that is also giving error. Can somebody please guide me about its replacement code. Thanks in advance Cheers TicArch

ASP.NET MVC2 Empty Web Application creates ASPNETDB database when I try to add user to my own databa

I created ASP.NET MVC2 Empty Web Application, I added my own database called 'Database1' and I added to this database Microsoft users, permissions etc. tables but when I create user in ASP.NET Configuration - it creates in catalog /App_Data database called 'ASPNETDB' and adds users to this database - I don't want that - I have my own database for that - what is going on ??In Web.config my ASP.NET MVC application I have only one connectionString - my own:<add name="Database1Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /> so what is going on ? How can I add users to my database 'Database1' ?

HtmlHelperExtensions in MVC2 return a HTML string, unencoded. In MVC3 this tring is encoded!

 HtmlHelperExtensions in MVC2 return a HTML string, unencoded. In MVC3 this string is encoded! How can I return unencoded HTML to a Razor view in MVC3? 

Asp.net MVC: How to call javascript function in Html.ActionLink

When I edit single recored in page, I use checkbox to get a selected row not every row with an actionlink element, but it seemed I cant make this way happen through calling javascript code(function GetSelectedRow() should return an id). Could anyone have a nice idea?<head runat="server"> <title>Index</title> <script type="text/javascript" language="javascript"> function GetSelectedRow() { var a = 0; var chkBoxes = document.getElementsByName("chkSelect"); var count = chkBoxes.length; for (var i = 0; i < count; i++) { if (chkBoxes[i].checked == true) a = chkBoxes[i].primaryKeyID; } return a; } </script> </head> <body> <div> <span style="width:20%"> <%: Html.ActionLink("Add", "Create")%> </span> <span> <%: Html.ActionLink("Edit", "Edit", new { id = GetSelectedRow()) %> </span> <span> <%: Html.ActionLink("Detial", "Details", new { id = GetSelectedRow() })%> </span> <span> <%: Html.ActionLink("Delete", "Delete", new { i

Html.ActionLink displayes unwanted virtual directory routing

My hosting provider has ASP.NET 3.5 and I'm using MVC 2.0. I have two domains on my account, http://www.domain1.com, and http://www.domain2.com, each has it's own virtual directory off of the root: / /domainone /domaintwo   Their routing commands for their httpd.ini rerouts http://www.domain1.com to http://www.domain1.com/domainone   If I type in the address bar http://www.domain1/Home/About, it works properly. The Problem My website links created using Html.ActionLink add the virtual directory. If you mouse over the About link in your standard MVC2.0 webapp, it displays as follows: http://www.domain1.com/domainone/Home/AboutAll of my testing and setup on my development machine doesn't have this virtual directory, and in the past my webhost didn't have this issue in the path. But since the move to their 'new' shared hosting platform, this is now what I'm having to deal with. How do I setup my ASP.NET MVC 2.0 web application to remove the unwanted virtual directory name from the path in my ActionLink controls? For example, when I mouse over the About link, I want the path to be http://www.domain1/Home/About ..or how can I add a new route handler to strip the virtual directory path from http://www.domain1/domainone/Home/About.   When I mouse over the Log On button on my logon page, the partial url domainone/Account/Lo

If-Else condition for ActionLink in Html Extension


In my code, I'm trying to write "if" condition in HTML.Helper instead of view.
Can you please tell me what mistake i'm doing?

Code on Controller

public static string IsSetup(this HtmlHelper helper, AModel aModel) 
string actionLink = string.Empty; 

 if (aModel.IsSetup) 
 { actionLink = "Html.ActionLink(\"" + "Continue for Setup\"" + "," + "\"Setup\"" + "," + "\"SetupController\") "; return actionLink; } 

 { actionLink = "Html.ActionLink(\"" + "Continue for Index\"" + "," + "\"Index\"" + "," + "\"SetupController\") "; 

 return actionLink; 


Code on View
        Please click to
        <%= Html.IsSetup(Model)%>
  // I'm expecting, <%= Html.ActionLink("Continue for Setup", "Setup", "SetupController") %>
  // but it renders as a TEXT like,  Please click to <%= Html.ActionLink("Continue for Setup", "Setup", "SetupController") %>

using dynamic text with HTML.Actionlink


Hello there my second post of the day this is becoming a habbit LOL  :)

as part of my web app i have a series of buttons created using HtmlActionlink


<%=Html.ActionLink("Swap User", "Index","Home")%></td>   

However my buttons need to be translated into difrent languages depending on the    country the user is in 

Im translating the button lable text fine in my controller and passing it into the view , but now im alittle stumped over syntax

Id like to replace "Swap User" above with 

multiple parameters in html.actionlink



how can i pass multiple parameters in html.actionlink?


MVC2: Change the default generated HTML when creating a strongly typed view


Is there any way to change the HTML that is generated by default when you create a strongly typed view in MVC2?

I currently get a structure like this:

            <div class="editor-label">
                <%: Html.LabelFor(model => model.category_id) %>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.category_id) %>
                <%: Html.ValidationMessageFor(model => model.category_id) %>

I want to change it to a structure like this:

                <div><%: Html.ValidationMessageFor(model => model.user_login) %></div>
                <div><%: Html.LabelFor(model => model.user_login) %></div>
                <div><%: Html.TextBoxFor(model => model.user_login) %></div>

Display html.actionlink through c


Hello guys,

I am noob and am trying to display Html.Actionlink through controller(MVC). Here is the example what am trying to do...

public string test(){

     string testString = "<%: html.ActionLink('click', 'test', new AjaxOptions() { UpdateTargetId = 'test' }) %>";

     return testString;


i want to display testString in view. but am not getting the actionlink in view..i can display anchors which is given below:-

public string test(){

     string testString = "<a href ="test"> click here</a>";

     return testString;


Hope reader is understanding what am trying to say...

any help would be appreciated.



ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.

Microsoft's Collaborative Application Markup Language (CAML) Loop

discovered an interesting error recently while working with Microsoft's Collaborative Application Markup Language (CAML) that, surprisingly, had received no ink. Partly what surprises me about this is that the error may require you to rewrite large sections of your code if you haven't previously considered this SharePoint limitation. I'll start with some context, but first of all the error is:

Integrating a Legacy Web Application in SharePoint

This month we will continue with the theme of deploying Microsoft's SharePoint as a company intranet by describing a method for integrating a legacy Web application inside a SharePoint site.

In many companies the intranet site is not just a home page with announcements. It houses Web applications used by many different departments. In last month's article, I built a page to search the employee table in Northwind (the sample database included in Microsoft's SQL Server). This month, I will move the Web pages used to add/remove records from the table into the SharePoint intranet.

MVC architecture in ASP.Net using C# and Microsoft Data Access Application block

The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes [Burbeck92]:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View. The view manages the display of information.

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

High-Performance .NET Application Development & Architecture

It has always been a goal of project architects to plan an effective strategy from the ground up in regards to an new application. All relevant factors are taken into consideration with respect to the application, from its design and layout to a functional website infrastructure. Pre-.NET strategies and design guidelines still effective now were developed with Microsoft's DNA (Distributed interNet Application) platform. This model successfully served the purpose of architecting N(any number of)-Tier (levels) applications. In its basic sense, as in most robust, distributed applications, you'll architect 3 main layers or Tiers: presentation, business rules and data access.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend