如何在 asp.net mvc 中创建引用某些 model.property 的链接?
我有强类型视图,我想创建引用模型的链接,该模型与该视图、某些属性(例如 Model.property)是强类型的。 我怎样才能做到这一点? 我用的是net4.0。 当我写“>时它什么也不做。 当我写 << 时,即使 Visual Studio 也无法识别它。 a href="<%: 并单击 ctrl+space 它不会带来任何内容。 这是我的观点
<%@ 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>
,我希望我的链接引用 Model.video。
这是我的控制器:
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);
}
}
}
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我是否 100% 关注您,但看起来您可能在没有模型的情况下定义了视图,例如:
您将需要这样的东西:
上面的键是 MyViewModel,它是您的视图模型。这应该有你所有的属性; MyViewModel.Video。
以下链接只是缺少链接文本。
当您在 和 之间添加一些内容时,它会使链接可见。
Not sure i follow you 100% but it looks like you might have your view defined without your model like:
And you will need something like this:
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.
when you added something in between the and the it made the link visible.