首页 \ 问答 \ 使用视图模型托管Razor View引擎(Hosting the Razor View Engine using a view model)

使用视图模型托管Razor View引擎(Hosting the Razor View Engine using a view model)

我想在ASP.NET MVC之外使用Razor View Engine为电子邮件生成HTML,我喜欢语法,当我在项目中使用Razor时,似乎没有必要使用另一个模板引擎。

所以我环顾四周,找到了如何做到这个指南.. http://blog.andrewnurse.net/2010/11/16/HostingRazorOutsideOfASPNetRevisedForMVC3RC.aspx

不幸的是我无法找到任何指定视图模型的方法,这很难过,因为我真的非常希望即使对于我的电子邮件也有强类型视图。

那么有没有办法用强类型视图模型解析ASP.NET MVC之外的Razor模板,或者它是不是很麻烦,不值得麻烦?


I'd like to use the Razor View Engine outside of ASP.NET MVC to generate HTML for emails, I like the syntax and it seems unnecessary to use another templating engine when I already have Razor in my project.

So I looked around and found this guide on how to do it.. http://blog.andrewnurse.net/2010/11/16/HostingRazorOutsideOfASPNetRevisedForMVC3RC.aspx

Unfortunately I can't find any way of specifying a view model, which is sad because I would really, really like to have strongly typed views even for my emails.

So is there any way of parsing Razor templates outside of ASP.NET MVC with strongly typed view models or is it so much trouble it's not worth the hassle?


原文:https://stackoverflow.com/questions/4448740
更新时间:2024-03-17 06:03

最满意答案

您错误地使用InputStream.available方法。 此方法不会尝试检索数据。 实际上,此方法的大多数实现始终返回0.请参阅Inputstream可用参考 。 我建议您只删除可用的检查,并根据需要让readLine阻止。 BufferedReader.ready也是如此 - 通常这并不表示您在尝试读取时会获得任何数据,因此此调用也没有用。


You use InputStream.available method incorrectly. This method will not try to retrieve data. Actually most implementations of this method always return 0. See Inputstream available reference. I recommend you just remove available checks and let readLine block as needed. The same goes for BufferedReader.ready - generally this does not show that you will get any data when attempting to read so this call is also not useful.

相关问答

更多
  • 对于第二个问题:创建一个新的final用于可运行的应用程序 while ((line = r.readLine()) != null) { total.append(line); Log.d("Server response", line.toString()); final String status = line; handler.post(new Runnable() { public void run() { if (statu ...
  • TCP数据在发送方和接收方均缓冲。 接收方的套接字接收缓冲区的大小决定了有多少数据可以在没有确认的情况下处于运行状态,并且发送方的发送缓冲区的大小决定了在发送方阻止或获取EAGAIN / EWOULDBLOCK之前可以发送多少数据,具体取决于阻塞/阻塞模式。 您可以将这些套接字缓冲区设置为最大2 ^ 32-1个字节,但如果将客户端接收缓冲区设置为高于2 ^ 16-1,则必须在连接套接字之前完成此操作,以便TCP窗口缩放可以在连接握手中协商,以便高16位可以发挥作用。 [服务器接收缓冲区在这里是不相关的,但是 ...
  • 至少你需要做一些错误检查。 也许这会有所帮助: $message = "api\tjson\tget\trooms\n"; $response = fsockopen("142.4.xxx.xxx", 5678, $errno, $errstr, 30); if (!$response) { echo "$errstr ($errno)
    \n"; } else { $out = "POST /script.php HTTP/1.1\r\n"; $out .= "Host: ...
  • 要在两台计算机之间建立连接,您需要两个地址和两个端口。 从你的代码: 服务器: vpbx.12connect.com:5060 : vpbx.12connect.com:5060 客户: **.***.**.**:? 客户端端口通常由操作系统选择,因此可能不是5060。 您可以以某种方式获取已使用的客户端端口并在SIP消息中传达此端口,或者在您的计算机上打开服务器,然后您可以将其绑定到特定端口(例如5060)。 对于SIP,我建议采用服务器方法,因为您必须在不连接服务器之前接收消息(INVITES)。 To ...
  • 参考此代码, import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; /** ...
  • 您错误地使用InputStream.available方法。 此方法不会尝试检索数据。 实际上,此方法的大多数实现始终返回0.请参阅Inputstream可用参考 。 我建议您只删除可用的检查,并根据需要让readLine阻止。 BufferedReader.ready也是如此 - 通常这并不表示您在尝试读取时会获得任何数据,因此此调用也没有用。 You use InputStream.available method incorrectly. This method will not try to ret ...
  • 如果您至少在Android v3.0上运行,则一次只能运行一个AsyncTask。 取消注释时,由于Receive正在运行,因此无法运行send。 一种替代方法是使用线程代替(例如,用于接收)。 查看此问题的详细信息 If you are running on Android v3.0 at least, you can run only one AsyncTask at a time. When uncommenting, since Receive is running, you cannot run ...
  • 我所做的只是对代码的一些修改。 我认为主要的变化是没有使用DataInputStream,因为文档明确表示不再使用这个数据结构中的readLine()。 http://download.oracle.com/javase/1.4.2/docs/api/java/io/DataInputStream.html#readLine%28%29 由于不需要,我也删除了授权内容。 如果您在某处运行此代码,您会注意到日志打印出HTTP响应。 String requestmsg = "GET /MOUNTPOINT" + ...
  • 是的,如果每次都创建一个新连接,这是安全的。 那说你的方法存在潜在的问题: TCP连接建立起来相当昂贵,因此您可能希望重新使用连接池的连接 如果您同时发出太多请求,则会耗尽端口/打开文件描述符,这会导致程序崩溃 您没有任何超时,因此最终可能会出现永远无法完成的孤立TCP连接(由于Go端的某些不良或网络问题) 我认为你最好不要使用HTTP(尽管有开销),因为已经编写了库以应对这些问题。 HTTP也可以调试,因为您只需卷曲端点来测试它。 就个人而言,我可能会选择gRPC 。 Yes this is safe i ...
  • 使用INADDR_ANY(或特定接口的地址)而不是INADDR_NONE。 INADDR_NONE是无符号常量,具有与有符号值-1相同的位模式,作为某些调用的错误指示返回。 Use INADDR_ANY (or a specific interface's address) rather than INADDR_NONE. INADDR_NONE is an unsigned constant with the same bit pattern as the signed value -1, returne ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)