Answered by:
sql help required on hyperlink

Question
-
I have a requirement to show value id values as hyperlink on UI
declare @text varchar(100)
declare @text studentid varchar(10)
set @text = select value from mastertable--only one row will be there
insert into mastertable(studentinfo)
values ('this is student @@id')
insert into table1(studentid)
values(replace(@text,''@@id",convert(varchar(100),@studentid)), @studentnewid)
output - "this is student "1-- value stored in table1 and here 1 is value and i put for understanding and it should be displayed as hyperlink on UI
- Edited by kdinuk Thursday, May 29, 2014 6:10 PM
Thursday, May 29, 2014 6:07 PM
Answers
-
MVC by default HTML encodes the input (in order to prevent cross site scripting attacks). There are ways to display info as is in MVC view. E.g. @Html.Raw
See
http://stackoverflow.com/questions/19980657/display-string-as-html-in-asp-net-mvc-view
Obviously, this is not the best way, but if you insist on returning HTML pre-formatted as a link, then it may be helpful.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles- Marked as answer by Fanny Liu Tuesday, June 10, 2014 1:23 AM
Thursday, May 29, 2014 9:05 PM
All replies
-
Hyperlink etc is a presentation requirement and can be handled at your front end application. You can use html tags like <a> at your presentation layer for putting hyperlink.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Thursday, May 29, 2014 6:43 PM -
I have used some this like this...but getting error...
insert into table1(studentid)
values(replace(@text,''@@id",convert(varchar(100),
'<a href=http://xyz.com/>' + cast(@studentid as varchar(20))+ '</a>')), @studentnewid)
I am getting error output on UI and this value displayed- this is student <a href=http://xyz.com/>1</a>
Need help please...
Thursday, May 29, 2014 6:53 PM -
Your URL should be built in the presentation layer. Your query just needs to return the display value, and the non-standard parts of the url:
select userid, urlpart, displayName from students
Then, in your presentation layer:
echo '<a href=www.xyz.com/student.php?id='+$userid+'>'+$displayName+'</a>';
- Proposed as answer by Naomi N Thursday, May 29, 2014 7:10 PM
Thursday, May 29, 2014 7:02 PM -
Agree and argued same thing. Is it not possible to display thru sql server?Thursday, May 29, 2014 7:07 PM
-
select '<a href=www.xyz.com/student.php?id='+convert(varchar,userid)+'>'+displayName+'</a>';
you *could* do it in a query, in exactly the same way.
Perhaps if you told us why you want to do this we might be able to offer a better solution?
Thursday, May 29, 2014 7:40 PM -
sorry, i tried, am getting same value displayed on UI.
my query is...
I have used some this like this...but getting error...
insert into table1(studentid)
values(replace(@text,''@@id",convert(varchar(100),
'<a href=http://xyz.com/>' + cast(@studentid as varchar(20))+ '</a>')), @studentnewid)
I am getting error output on UI and this value displayed- this is student <a href=http://xyz.com/>1</a>
Thursday, May 29, 2014 7:58 PM -
After a href = we need double quotes which are currently missing, e.g.
<a href = "http://....xyz.com/1">This is student 1</a>
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articlesThursday, May 29, 2014 8:04 PM -
Tried that as well
still displaying <a href = "http://....xyz.com/1">This is student 1</a> on UI
Thursday, May 29, 2014 8:09 PM -
Well, what is used to develop UI? Most likely you don't want to return this text from SQL Server (as many people already told you), but create hyperlink in UI directly.
What is your development platform, MVC or plain ASP.NET?
You may get better answer if you ask your question from the client's application perspective as how to make the ID hyperlink. It is not a job for SQL Server.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articlesThursday, May 29, 2014 8:15 PM -
I understand.
You want the hyperlink to display. You're seeing the whole string in your display layer.
SSMS (and most other editors) will not display HTML as HTML, it will only display the plain text.
This is an issue with your display layer, not your SQL. You should ask you question with the display layers support team. If you tell us what your display layer is, someone *might* be able to help you, but you'll more than likely have better luck with them.
- Edited by Patrick Hurst Thursday, May 29, 2014 8:17 PM
Thursday, May 29, 2014 8:16 PM -
It is .net application developed using MVCThursday, May 29, 2014 8:23 PM
-
What is used in the view to display the info? I think you may want to review some MVC tutorials, you don't want to return this information as linked text in SQL Server, it's easy to set link in MVC instead.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articlesThursday, May 29, 2014 8:46 PM -
Quick google search provided this link
http://stackoverflow.com/questions/1624697/how-to-render-plain-html-links-in-asp-net-mvc-loop
I think you can run more searches on this question, as it may be even easier.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articlesThursday, May 29, 2014 8:48 PM -
I have gone thru link and i see .net, i want todo this from sql server .net developer doesn't need todo.Thursday, May 29, 2014 8:59 PM
-
MVC by default HTML encodes the input (in order to prevent cross site scripting attacks). There are ways to display info as is in MVC view. E.g. @Html.Raw
See
http://stackoverflow.com/questions/19980657/display-string-as-html-in-asp-net-mvc-view
Obviously, this is not the best way, but if you insist on returning HTML pre-formatted as a link, then it may be helpful.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles- Marked as answer by Fanny Liu Tuesday, June 10, 2014 1:23 AM
Thursday, May 29, 2014 9:05 PM