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

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

Display html.actionlink through c

Posted By:      Posted Date: October 16, 2010    Points: 0   Category :ASP.Net

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.



View Complete Post

More Related Resource Links

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


display codes (asp or html) on web page

hello.....i am wishing to display asp or html codes on my web page. actually i am working on article project and article includes codes too. still i am using <iframe> but not looking soo good.i am also wishing to dispaly codes in a way that can be expand or collapsed using (+) sing, as you also know. or tell me any alternative to accomplish. thanks in advance

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

Razor. Display conditional Html

Hello,I have the following code on a View using Razor view engine: @if(View.Section == CMSSection.Home) { Html.ActionLink("Home", MVC.CMS.Home.Index()) } else { <span>Home</span> }I keep getting the error:Compiler Error Message: CS1002: ; expectedWhat am I missing?Thank you,Miguel

VWD2010, MVC2, Html.ActionLink and Application[]



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

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") %>

convert doc to html and display it


i have create a small program that upload a document to a file path and then convert it to an html doc in whith it create me an html file and a folder with the same name that include the style of the document and photos if in the original document they are any photos.

what i want to know is if we upload the document and they are photos when i click on the html file that is been create i can see the photos, but when i include the html file in my asp.net code i can not see the photos and only the text document is been show.

is it possible to view and the photo or not?


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?


Html Display


I am passing JSON data to client side usign ajax call

In callback i get the result like

 success: function (txt) {

ln list there is two other list Grade,Title

Like list --> Grade --> 2,3
       Title --> Maths,Science

now i want to make Html for this

like Grade, Course
      2   Maths
 3   Science

How can i achive this using jQuery or JS to make html and display it

Display Binary PDf in HTML/Text



I am saving user uploaded PDF files in SQL server using varbinary datatype. There is totally no problem in saving in binary and retrieving in PDF. But due to one specific requirement (which i cant change) i to need to fetch binary PDF and display in HTML or atleast get in string form.

Is it possible? If yes how.

Rite now i m opening PDF files like code written below. But it opens a PDF reader in browser. I want to display the data of PDF in plain text instead in PDF reader.

bytedata = (byte[])dsPrograms.Tables[0].Rows[0]["PDFFile"];
                PdfReader pdfReader = new PdfReader(bytedata);
                Response.ContentType = "application/pdf";
                PdfStamper pdfStamper = new PdfStamper(pdfReader, Response.OutputStream, '\0', true);
                AcroFields pdfFormFields = pdfStamper.AcroFields;
                AcroFields docFields = pdfStamper.AcroFields;
                pdfStamper.FormFlattening = false;

Publishing HTML and RichTextField display HTML code - not rendering


Hi there, 

I have several custom columns of type "Publishing HTML", and a page layout several controls which point to the columns. :

<SharePointWebControls:RichTextField DisableInputFieldLabel="True"  FieldName="WheelImage" runat="server"></SharePointWebControls:RichTextField>


The problem is that in the end result, the page shows escaped HTML (eg. <p></p>) rather than the rendered output I would expect. 


Oddly - when it edit mode - they render fine, showing the rendered output. But in the 'reader' view, it shows the raw HTML. 


I have also checked the 'edit html source' in edit mode - and it looks fine, like HTML. But the browser source of the output page shows escaped html: &lt;br/&gt;


I found this describing the same problem, but its not a solution - as this happens on any browser:




Anyone any ideas?






RichHtmlField showing html markup in display mode



Can somebody provide a solution to my problem? I have a RichHTMLField that I created in sharepoint designer/Visual Studios. After I got everything to work. I've tested it on several computers and it worked fine. When I tried it on my computer, my RichHtmlField in my sharepoint  shows html markup in display mode. In the edit mode, it shows perfectly fine and well formatted. When I save and publish it out, the published mode shows the actual HTML markup like you would see in WYSIWYG interface.

Any solutions?

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.

GridView inline Master/Detail record display

This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time (ya, right) you may want to review the source code.

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.
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