开发者

Creating an external link in ASP.NET MVC 2 from model properties

I'm trying to build a link to an external website using some properties of my model class in my view page, e.g. I want it to render as something like -

< a href="http://twitter.com/home?status=Currently reading http://www.mywebsite.com/post-id">Twitter < /a>

where post-id would be pulled from the model (I'm using a strongly typed view model here - I can't use ViewData as there's a list of items being pulled back all of which need seperate links).

I tried doing < a href="&开发者_Python百科lt;% model.PermaLink(); %>">, where PermaLink is just some string, however the value doesn't get picked up.

If I try < a href="<%= model.PermaLink %>">, I get an error - CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid arguments

Is there any way to do this? I tried adding the runat="server" attribute, however this just linked to my local site and controller/model actions.


Is this within an MVC ViewPage, based on the ViewPage class, or is it a WebForms page?

the < a href="<%= model.PermaLink %>"> syntax is correct for an MVC Page


Whoops, hadn't setup my property properly, was just using a regular getter. Maybe I should go back to Java :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜