Reputation: 2205
I have strong-type view, I want to create link that refers to Model, which is strong-typed with that view, some property (e.g Model.property). How can I do that? I use net4.0. when I write "> it do nothing. Even visual studio don't recognize it when I write < a href="<%: and click ctrl+space it doesn't bring anything. This is my view
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<UrlParser.Models.Parse>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Show</title>
</head>
<body>
<h1> Title: </h1>
<%: Model.title %>
<br />
<h1> Description: </h1>
<%: Model.description %>
<% if(!Model.video.Equals("")) { %>
<h2> Video:</h2>
<%: Model.video %>
<a href="<%: Model.video %>"> </a>
<% } %>
</body>
</html>
I want my link refer to Model.video.
These is my controler:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UrlParser.Models;
namespace UrlParser.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(GetUrl getUrl)
{
// int i = 0;
Parse prs = new Parse(getUrl.url);
return View("Show", prs);
}
}
}
Upvotes: 1
Views: 2746
Reputation: 846
Not sure i follow you 100% but it looks like you might have your view defined without your model like:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
And you will need something like this:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MyViewModel>" %>
The key above is the MyViewModel which is you view model. This should have all your properties; MyViewModel.Video.
The following link was just missing the link text.
<a href="<%: Model.video %>"> </a>
when you added something in between the and the it made the link visible.
Upvotes: 1