Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,

Is there a possibility to convert MVC html Helper to html Link. So what I want exactly to do:
I have this html helper:

HTML
@Html.LinkTo(MVCController, MVCAction, new { area = MVCArea, id = row.Id, menuId = ViewBag.CurrentMenu }, row.Id, columnValue, col.Data.Name, DynamicTypeName). 

I want to convert to something like this: 'a href= "ControllerName/controlleraction/`+ parameter1 .... > /a>'. Where controller name is MVCController, controller action is MVCAction and the others variable are parameters that are sent to controller.
I have a result of the search, displayed in the table, in which each row has a link to the controller sent as a parameter. Now I want to replace the existing table with a Jquery datatable and send ajax request to the server which returns a Json object. That Json object should contain the link that is created with:
HTML
@Html.LinkTo(MVCController, MVCAction, new { area = MVCArea, id = row.Id, menuId = ViewBag.CurrentMenu }, row.Id, columnValue, col.Data.Name, DynamicTypeName).
"

My question is: Is it possible to create in controller action (which return json object) a string that will be equal to the string created with the @Html.LinkTo helper?

Thanks in advance,
Regards Stole
Posted
Updated 25-Aug-14 8:02am
v4

If your string is ready and you just want to return it, use something like:

SQL
public ActionResult YourActionMethod() {
    return Content("Put your string here!");
}


For more, please look into "ContentResult" section at:
http://www.c-sharpcorner.com/uploadfile/ff2f08/actionresult-return-type-in-mvc-3-0/[^]

Same web page describes to send result as JSON too. Thanks.
 
Share this answer
 
v4
Comments
stmk69 25-Aug-14 9:13am    
Probably I didn't explain my problem clearly.
I would like to build string according to the @Html.LinkTo helper. For example if I have 3 rows, I want to have 3 different links because of the different parameters.

¦1¦ aaa1 ¦ aal2 ¦ link = /controller/action/1¦ use first column as a parameter
¦2¦ bbb1 ¦ bbl2 ¦ link = /controller/action/2¦ use first column as a parameter
¦3¦ ccc1 ¦ ccl2 ¦ link = /controller/action/3¦ use first column as a parameter

Then return that link in json result and use it in jQuery datatable.
If it is necessary I will send the code in my view that should i replace.
Regards
Stole
Snesh Prajapati 25-Aug-14 9:23am    
I am not sure why you are designing like that. I have written as example on CRUD with MVC and jQuery with different approach at http://www.codeproject.com/Articles/678222/CRUD-Operations-using-Partial-V ....Hope that would be useful....if not then explain your scenario in detail and put some more code (client and server side) in question itself. Thanks.
Thanks for the answer, but it is solved it in meantime.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900