MVC HtmlHelpers麻烦剃刀 [英] MVC HtmlHelpers trouble with Razor
问题描述
我工作的一个非营利性捐赠平台,我使用MVC首次。我已经得到了它挂在大多数情况下,但现在我有,我不知道如何解决的一个问题。我使用的AthorizeNet.Helpers类,当我从expamples添加code,它工作在大多数情况下,除了其形式,并把它上面的标记但它把表单域在正确的位置。我试图找出如何呈现在正确的位置的标记。
@using AuthorizeNet.Helpers;@using(Html.BeginSIMForm(http://127.0.0.1:4768,1.99M,xxx_key,yyy_key,真))
{
@ Html.Raw(Html.CheckoutFormInputs(真))
@ Html.Hidden(ORDER_ID,1234)
<输入类型=提交值=支付/>
}
这是它的外观在HTML输出:
<形式的行动='https://test.authorize.net/gateway/transact.dll'方法='后'>
<输入类型=隐藏的名字='x_fp_hash'值='6bef386eaa89944efd62b47b86042910'\\>
<输入类型=隐藏的名字='x_fp_sequence'值='117'\\>
<输入类型=隐藏的名字='x_fp_timestamp'值='xxx_key'\\>
<输入类型=隐藏的名字='x_login'值='yyy_key'\\>
<输入类型=隐藏的名字='x_amount'值='1.99'\\>
<输入类型=隐藏的名字='x_relay_url'值='http://127.0.0.1:4768'\\>
<输入类型=隐藏的名字='x_relay_response'值='TRUE'\\>
< /形式为GT;<!DOCTYPE HTML>
< HTML和GT;
<身体GT;
< H2>付款信息< / H>
< DIV的风格=边界:1px的固体#990000;填充:12px的;保证金底:24px的;背景色:#FFFFCC;宽度:300像素'>测试模式和LT; / DIV>
< DIV的风格=浮动:左;宽度:250像素;'>
<标签>信用卡号码和LT; /标签>
< DIV ID ='CreditCardNumber'>
<输入类型=文本大小=28NAME ='x_card_num'值='4111111111111111'ID ='x_card_num/>
< / DIV>
< / DIV>
< DIV的风格=浮动:左;宽度:70像素;'>
<标签>&EXP LT; /标签>
< DIV ID ='CreditCardExpiration'>
<输入类型=文本大小=5MAXLENGTH =5NAME ='x_exp_date'值='0116'ID ='x_exp_date/>
< / DIV>
< / DIV>
< DIV的风格=浮动:左;宽度:70像素;'>
<标签>&CCV LT; /标签>
< DIV ID ='CCV'>
<输入类型=文本大小=5MAXLENGTH =5NAME ='x_card_ code'ID ='x_card_ code'的值='123'/>
< / DIV>
< / DIV><输入ID =ORDER_IDNAME =ORDER_ID类型=隐藏值=1234/> <输入类型=提交值=支付/>
这种问题通常发生时被直接写入到输出流的帮手是为ASP.NET MVC 1(书面和括在使用助手是直接写入输出流的大部分时间)。在ASP.NET MVC 1你可以使用此写入输出流:
htmlHelper.ViewContext.HttpContext.Response.Output
在以后ASP.NET MVC版本中,你应该使用这样的:
htmlHelper.ViewContext.Writer
这确保剃刀兼容性。如果你有机会到AuthorizeNet.Helpers源$ C $ C,你可以自己修复它,如果你没有比你有联系的作者固定的。
I'm working on a non-profit donation platform and I'm using MVC for the first time. I've got the hang of it for the most part but right now I'm having a problem that I dont know how to address. I'm using the AthorizeNet.Helpers class and when I add the code from the expamples, it works for the most part except for it takes the form and puts it ABOVE the tag however it puts the form fields in the correct place. I'm trying to figure out how to render the tag in the correct place.
@using AuthorizeNet.Helpers;
@using (Html.BeginSIMForm("http://127.0.0.1:4768", 1.99M, "xxx_key", "yyy_key", true))
{
@Html.Raw(Html.CheckoutFormInputs(true))
@Html.Hidden("order_id", "1234")
<input type = "submit" value = "Pay" />
}
This is how it looks in HTML output:
<form action = 'https://test.authorize.net/gateway/transact.dll' method = 'post'>
<input type = 'hidden' name = 'x_fp_hash' value = '6bef386eaa89944efd62b47b86042910' \>
<input type = 'hidden' name = 'x_fp_sequence' value = '117'\>
<input type = 'hidden' name = 'x_fp_timestamp' value = 'xxx_key' \>
<input type = 'hidden' name = 'x_login' value = 'yyy_key' \>
<input type = 'hidden' name = 'x_amount' value = '1.99' \>
<input type = 'hidden' name = 'x_relay_url' value = 'http://127.0.0.1:4768' \>
<input type = 'hidden' name = 'x_relay_response' value = 'TRUE' \>
</form><!DOCTYPE html>
<html>
<body>
<h2>Payment Information</h2>
<div style = 'border: 1px solid #990000; padding:12px; margin-bottom:24px; background-color:#ffffcc;width:300px'>Test Mode</div>
<div style = 'float:left;width:250px;'>
<label>Credit Card Number</label>
<div id = 'CreditCardNumber'>
<input type = 'text' size = '28' name = 'x_card_num' value = '4111111111111111' id = 'x_card_num'/>
</div>
</div>
<div style = 'float:left;width:70px;'>
<label>Exp.</label>
<div id = 'CreditCardExpiration'>
<input type = 'text' size = '5' maxlength = '5' name = 'x_exp_date' value = '0116' id = 'x_exp_date'/>
</div>
</div>
<div style = 'float:left;width:70px;'>
<label>CCV</label>
<div id = 'CCV'>
<input type = 'text' size = '5' maxlength = '5' name = 'x_card_code' id = 'x_card_code' value = '123' />
</div>
</div><input id="order_id" name="order_id" type="hidden" value="1234" /> <input type = "submit" value = "Pay" />
This kind of problem usually happens when a helper which is writing directly to output stream was written for ASP.NET MVC 1 (and helpers that are enclosed in using are writing directly to output stream most of the time). In ASP.NET MVC 1 you could write to output stream by using this:
htmlHelper.ViewContext.HttpContext.Response.Output
In later ASP.NET MVC version you should be using this:
htmlHelper.ViewContext.Writer
That ensures Razor compatibility. If you have access to AuthorizeNet.Helpers source code you can fix it by yourself, if you don't than you have to contact authors for fixing it.
这篇关于MVC HtmlHelpers麻烦剃刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!