【发布时间】:2011-09-11 18:51:59
【问题描述】:
控制器是:
public class HomeController : Controller
{
public ActionResult LogOn()
{
return View();
}
[HttpPost]
public ActionResult LogOn(string captcha)
{
if (captcha == HttpContext.Session["captcha"].ToString())
return Content("ok");
else
return Content("failed");
}
public CaptchaImageResult ShowCaptchaImage()
{
return new CaptchaImageResult();
}
}
观点是:
<%using (Html.BeginForm())
{ %>
<p><img src="/Home/ShowCaptchaImage" /></p>
<p>Please enter the string as shown above:</p>
<p><%= Html.TextBox("captcha")%></p>
<p><input type="submit" value="Submit" /></p>
<% } %>
一切顺利,验证码图像被渲染(CaptchaImageResult 在响应流中写入一个jpg)。但如果我使用剃刀视图引擎,则不会呈现验证码图像。
如何解决?
还有一件事:这是显示验证码的好方法吗?
稍后编辑:<img src=@Href("../../Home/ShowCaptchaImage") /> 工作正常。
问题不是因为剃刀而是因为在第一个示例中我使用的是 Visual Studio 开发服务器,而在第二个示例中我使用的是 IIS
【问题讨论】:
-
使用razor视图引擎时,返回的Html是什么样的?
标签: c# .net asp.net-mvc-3 razor virtual-path