Html.BeginRouteForm Helper Can not Create <form> Tag

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 лет назад
Hi, I want to develop all in one (Turkish banks) payment plugin.
I'm trying to put a button and dropdownlistbox on the "PaymentInfo" form. When clicked this button appropriate bank form shows.
I use "@using (Html.BeginRouteForm" html helper to create custom form like "GoogleCheckout" PaymentInfo form. But there is no appropriate form tag in rendered html tags.

<!-- My PaymentInfo form -->
@{
    Layout = "";
}
@model Nop.Plugin.Payments.IsBank.Models.PaymentInfoModel
@using Nop.Web.Framework;


    <table width="100%" cellspacing="2" cellpadding="1" border="0">
        <tr>
            <td>
                @Html.NopLabelFor(model => model.Banks, false):
            </td>
            <td>
                @Html.DropDownListFor(model => model.Bank, Model.Banks, new { @class = "dropdownlists" })
            </td>
        </tr>              
    </table>
    <div class="clear"> </div>
@using (Html.BeginRouteForm("Plugin.Payments.IsBank.KartBilgileri", FormMethod.Post, new { id = "form-taksitpuan" }))
{
    <div id="taksitPuanGoster" style="cursor:pointer;width:132px;height:22px;background-color:yellow;">Taksit seçenekleri için tıklayın...</div>
    <div class="clear"> </div>
}
<script type="text/javascript">
    $(document).ready(function () {
        $('#taksitPuanGoster').click(function () {
            $("#form-taksitpuan").submit();
        });
    });
</script>



<!-- Result rendered html output -->
<div class="checkout-data">
<form method="post" action="/checkout/paymentinfo">    <!--  ONLY THIS form TAG -->
<div class="payment-info">
<div class="body">
<table cellspacing="2" cellpadding="1" border="0" width="100%">
<tbody>
</tbody>
</table>
<div class="clear"> </div>
<div id="taksitPuanGoster" style="cursor: pointer; width: 132px; height: 22px; background-color: yellow;">Taksit seçenekleri için tıklayın...</div>
<div class="clear"> </div>
<script type="text/javascript">
</script>
</div>
<div class="clear"> </div>
<div class="select-button">
</div>
</div>
<div class="clear"> </div>
<div class="error-block">
</div>
<div class="clear"> </div>
<div class="order-summary-title"> Order summary </div>
<div class="clear"> </div>
<div class="order-summary-body">
</div>
</form>
</div>
12 лет назад
When the page is called it renders the appropriate data but the HTML side does not include the opening and closing FORM tags which will be required in order to save the modifications. Any clue as to what I may be missing?
12 лет назад
calacula wrote:
When the page is called it renders the appropriate data but the HTML side does not include the opening and closing FORM tags which will be required in order to save the modifications. Any clue as to what I may be missing?


I'm not sure why this is happening, but it could be because you're not actually allowed to nest forms. If you do nest forms you could see some weird behaviors. What you should try and do instead is separate out the form inputs so they are not nested and use CSS and HTML to get the same look and feel you desire.

You can also use javascript to give you functionality without modifying your design.
12 лет назад
Thank you Skyler. I found this..
I found the root cause to be my master page. When adding the master page I selected a standard master page NOT one from the MVC3 list!. I proceeded to delete the existing master page and added the proper one (from the MVC3 list) refreshed the page and the tags were rendered properly.
And I start from this point.
Delete my PaymentInfo.cshtml and copy paste GoogleCheckout PaymentInfo.cshtml
Pasted my html codes on new PaymentInfo.cshtml file.
It worked! But I don't understand anything..

Thank you.
12 лет назад
it doesn't work. I don't understand anything.
http://forums.asp.net/t/1740810.aspx/1?Missing+Form+Tag+in+Partial+View+MVC+3
12 лет назад
calacula wrote:
it doesn't work. I don't understand anything.

Could you share your project?
12 лет назад
PaymentInfo.cshtml

@{
    Layout = "";
}
@model Nop.Plugin.Payments.IsBank.Models.PaymentInfoModel
@using Nop.Web.Framework;
@{
    
    string imageUrl = "";

    
    imageUrl = string.Format("http://www.lifereboot.com/wp-content/uploads/go-button.jpg");
  
}
<!-- THERE IS NO <form> TAG HTML OUTPUT OR IT'S NOT SUBMIT.  (if I see with firebug there is no form tag, but right click view source then there is the form tag) -->
@using (Html.BeginRouteForm("Plugin.Payments.IsBank.SubmitButton", FormMethod.Post, new { id = "form-googlecheckout" }))
{
    <img id="googleCheckoutImage" alt="" src="@Html.Raw(imageUrl)" style="cursor:pointer;" />
}
<script type="text/javascript">

    $(document).ready(function () {
        $('#googleCheckoutImage').click(function () {
            $("#form-googlecheckout").submit();
        });
    });
</script>



RouteProvider.cs

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;

namespace Nop.Plugin.Payments.GoogleCheckout
{
    public partial class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Plugin.Payments.GoogleCheckout.Configure",
                 "Plugins/PaymentGoogleCheckout/Configure",
                 new { controller = "PaymentGoogleCheckout", action = "Configure" },
                 new[] { "Nop.Plugin.Payments.GoogleCheckout.Controllers" }
            );

            routes.MapRoute("Plugin.Payments.GoogleCheckout.PaymentInfo",
                 "Plugins/PaymentGoogleCheckout/PaymentInfo",
                 new { controller = "PaymentGoogleCheckout", action = "PaymentInfo" },
                 new[] { "Nop.Plugin.Payments.GoogleCheckout.Controllers" }
            );
            
            
            //Submit Google Checkout button
            routes.MapRoute("Plugin.Payments.GoogleCheckout.SubmitButton",
                 "Plugins/PaymentGoogleCheckout/SubmitButton",
                 new { controller = "PaymentGoogleCheckout", action = "SubmitButton" },
                 new[] { "Nop.Plugin.Payments.GoogleCheckout.Controllers" }
                 );

            //Notification
            routes.MapRoute("Plugin.Payments.GoogleCheckout.NotificationHandler",
                 "Plugins/PaymentGoogleCheckout/NotificationHandler",
                 new { controller = "PaymentGoogleCheckout", action = "NotificationHandler" },
                 new[] { "Nop.Plugin.Payments.GoogleCheckout.Controllers" }
            );
        }
        public int Priority
        {
            get
            {
                return 0;
            }
        }
    }
}


PaymentIsBankController.cs

using Nop.Plugin.Payments.IsBank.Models;
using Nop.Plugin.Payments.IsBank.Validators;
using Nop.Services.Localization;
using Nop.Web.Framework;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web.Configuration;
using System.Web.Mvc;
using Nop.Core;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Services.Configuration;
using Nop.Services.Customers;
using Nop.Services.Directory;
using Nop.Services.Logging;
using Nop.Services.Orders;
using Nop.Services.Payments;
using Nop.Web.Framework.Controllers;
using ePayment;

namespace Nop.Plugin.Payments.IsBank.Controllers
{
    public class PaymentIsBankController : BaseNopPaymentController
    {
        private readonly ISettingService _settingService;
        private readonly ILocalizationService _localizationService;
        private readonly IsBankPaymentSettings _isbankPaymentSettings;

        private readonly IWorkContext _workContext;
        private readonly IOrderProcessingService _orderProcessingService;
        private readonly IPaymentService _paymentService;
        private readonly PaymentSettings _paymentSettings;

        public PaymentIsBankController(ISettingService settingService,
            ILocalizationService localizationService, IsBankPaymentSettings isbankPaymentSettings,
            IWorkContext workContext, IOrderProcessingService orderProcessingService,
            IPaymentService paymentService, PaymentSettings paymentSettings)
        {
            this._settingService = settingService;
            this._localizationService = localizationService;
            this._isbankPaymentSettings = isbankPaymentSettings;

            this._orderProcessingService = orderProcessingService;
            this._paymentService = paymentService;
            this._paymentSettings = paymentSettings;
            this._workContext = workContext;
        }
        
        [AdminAuthorize]
        [ChildActionOnly]
        public ActionResult Configure()
        {
            var model = new ConfigurationModel();
            model.TransactModeId = Convert.ToInt32(_isbankPaymentSettings.TransactMode);
            model.AdditionalFee = _isbankPaymentSettings.AdditionalFee;
            model.TransactModeValues = _isbankPaymentSettings.TransactMode.ToSelectList();
            
            return View("Nop.Plugin.Payments.IsBank.Views.PaymentIsBank.Configure", model);
        }

        [HttpPost]
        [AdminAuthorize]
        [ChildActionOnly]
        public ActionResult Configure(ConfigurationModel model)
        {
            if (!ModelState.IsValid)
                return Configure();
            
            //save settings
            _isbankPaymentSettings.TransactMode = (TransactMode)model.TransactModeId;
            _isbankPaymentSettings.AdditionalFee = model.AdditionalFee;
            _settingService.SaveSetting(_isbankPaymentSettings);

            model.TransactModeValues = _isbankPaymentSettings.TransactMode.ToSelectList();

            return View("Nop.Plugin.Payments.IsBank.Views.PaymentIsBank.Configure", model);
        }

        [ChildActionOnly]
        public ActionResult PaymentInfo()
        {
            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            if (cart.Count == 0)
                return Content("");

            bool minOrderSubtotalAmountOk = _orderProcessingService.ValidateMinOrderSubtotalAmount(cart);
            if (!minOrderSubtotalAmountOk)
                return Content("");

            var model = new PaymentInfoModel();

            model.Bankalar.Add(new SelectListItem()
            {
                Text = "Akbank",
                Value = "Akbank",
            });
            model.Bankalar.Add(new SelectListItem()
            {
                Text = "Garanti",
                Value = "Garanti",
            });
            model.Bankalar.Add(new SelectListItem()
            {
                Text = "Isbank",
                Value = "Isbank",
            });
          

            return View("Nop.Plugin.Payments.IsBank.Views.PaymentIsBank.PaymentInfo", model);
        }

        [ChildActionOnly]
        public ActionResult TaksitPuan()
        {
            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            if (cart.Count == 0)
                return Content("");

            bool minOrderSubtotalAmountOk = _orderProcessingService.ValidateMinOrderSubtotalAmount(cart);
            if (!minOrderSubtotalAmountOk)
                return Content("");

            var model = new TaksitPuanModel();

            model.Taksitler.Add(new SelectListItem()
            {
                Text = "3 ay",
                Value = "3",
            });
            model.Taksitler.Add(new SelectListItem()
            {
                Text = "6 ay",
                Value = "6",
            });
            model.Taksitler.Add(new SelectListItem()
            {
                Text = "9 ay",
                Value = "9",
            });

            return View("Nop.Plugin.Payments.IsBank.Views.PaymentIsBank.TaksitPuan", model);
        }

        //KartBilgileri
        //[HttpPost]
        //[AdminAuthorize]
        //[ChildActionOnly]
        public ActionResult SubmitButton(PaymentInfoModel model)
        {
            //if (!ModelState.IsValid)
            //    return Configure();

            //var _model = new TaksitPuanModel();

            //_model.CardCode = model.CardCode;
            //_model.CardholderName = model.CardholderName;
            //_model.CardNumber = model.CardNumber;
            //_model.CreditCardType = model.CreditCardType;
            //_model.ExpireMonth = model.ExpireMonth;
            //_model.ExpireYear = model.ExpireYear;

            //_model.Taksitler.Add(new SelectListItem()
            //{
            //    Text = "3 ay",
            //    Value = "3",
            //});
            //_model.Taksitler.Add(new SelectListItem()
            //{
            //    Text = "6 ay",
            //    Value = "6",
            //});
            //_model.Taksitler.Add(new SelectListItem()
            //{
            //    Text = "9 ay",
            //    Value = "9",
            //});
            //_model.PuanKullanim = "testPuanKullanim";
              

            //return View("Nop.Plugin.Payments.IsBank.Views.PaymentIsBank.TaksitPuan", _model);
            return Content("bla bla");
        }
        

        [ChildActionOnly]
        public ActionResult CheckOutConfirm()
        {
            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            if (cart.Count == 0)
                return Content("");

            bool minOrderSubtotalAmountOk = _orderProcessingService.ValidateMinOrderSubtotalAmount(cart);
            if (!minOrderSubtotalAmountOk)
                return Content("");

            var model = new CheckOutConfirmModel();

            model.TaksitListeleri.Add(new SelectListItem()
                {
                    Text = "3 ay",
                    Value = "3",
                });
            model.TaksitListeleri.Add(new SelectListItem()
            {
                Text = "6 ay",
                Value = "6",
            });
            model.TaksitListeleri.Add(new SelectListItem()
            {
                Text = "9 ay",
                Value = "9",
            });

            return View("Nop.Plugin.Payments.IsBank.Views.PaymentIsBank.CheckOutConfirm", model);
        }
        

        [NonAction]
        public override IList<string> ValidatePaymentForm(FormCollection form)
        {
            var warnings = new List<string>();

            //validate
            var validator = new PaymentInfoValidator(_localizationService);
            var model = new PaymentInfoModel()
            {
                CardholderName = form["CardholderName"],
                CardNumber = form["CardNumber"],
                CardCode = form["CardCode"],
            };
            var validationResult = validator.Validate(model);
            if (!validationResult.IsValid)
                foreach (var error in validationResult.Errors)
                    warnings.Add(error.ErrorMessage);

                        

            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();


            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.IsBank") as IsBankPaymentProcessor;
            if (processor == null ||
                !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
                throw new NopException("IsBank Payment module cannot be loaded");


            return warnings;
        }

        [NonAction]
        public override ProcessPaymentRequest GetPaymentInfo(FormCollection form)
        {
            var paymentInfo = new ProcessPaymentRequest();
            paymentInfo.CreditCardType = form["CreditCardType"];
            paymentInfo.CreditCardName = form["CardholderName"];
            paymentInfo.CreditCardNumber = form["CardNumber"];
            paymentInfo.CreditCardExpireMonth = int.Parse(form["ExpireMonth"]);
            paymentInfo.CreditCardExpireYear = int.Parse(form["ExpireYear"]);
            paymentInfo.CreditCardCvv2 = form["CardCode"];
            paymentInfo.RecurringTotalCycles = int.Parse(form["TaksitListesi"]);  // installment
                                          
            return paymentInfo;
          
        }
    }
}
12 лет назад
Selam
Hata aldığın mesaj tam olarak nedir  ?Ayrıca gördüğüm kadarı ile akbank içerisinde garanti var .garanti kendi altyapısını kullanıyor...
12 лет назад
Html.BeginRouteForm  kodu oluşturması gereken <form...> tagını oluşturmuyor. Acaba nested form tagları kullanılamıyor mu diye düşünüyorum ama google checkout a baktığımda aynı şekilde paymentinfo.cshtm in içinde kullanılmış. Aynı kodları kullanıyorum fakat sonuç alamıyorum.
yapmak istediğim şeyi şöyle de düşünebilirsin 3d ödeme sistemi için post metodu ile bir form oluşuturuyoruz ve içine hidden tipinde birtakım bilgilerimizi (üye işyeri numarası, şifresi vs.) yerleştiriyoruz. bu form üzerinde submit butonu tıklandığında bu formu olduğu gibi bankanın serverına post ediyoruz.
işte bu formu oluşturmak için olması gereken <form..> tahları "Html.BeginRouteForm" komutları ile oluşmuyor. acaba nerede hata yapıyor olabilirim?
12 лет назад
Please read this article.

PaymentMethodType (IPaymentMethod interface) property indicates payment method type. Currently there are three types. Standard used by payment methods when a customer is not redirected to a third-party site. Redirection is used when a customer is redirected to a third-party site. And Button is similar to Redirection payment methods. The only difference is used that it's displayed as a button on shopping cart page (for example, Google Checkout).

What payment method plugin type do you want to implement? Button (like Google Checkout) or Redirection (like PayPal Standard)? I see that your PaymentMethodType is set to Standard (none of the two types mentioned above). confusing...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.