Sitefinity CMS: Html.BeginFormSitefinity with external URL?

为君一笑 提交于 2019-12-24 03:09:23

问题


I'm hoping someone can help me here - I'm trying to set up a basic MVC widget for Sitefinity that will POST to an external URL to log the user in there. The problem is if I use regular HTML to do this, the widget will only work in pure MVC mode thanks to the way WebForms deals with forms.

I googled around a bit and found people explaining that with the regular "BeginForm" you can specify an external action URL thusly:

Html.BeginForm(null, null, FormMethod.Post, new { @action="EXTERNAL_URL" })

Which produces the following opening form tag:

<form action="EXTERNAL_URL" method="post">

This works very nicely, but still outputs a regular HTML form which doesn't work with Sitefinity, so Sitefinity has it's own method to produce forms that will work in Hybrid mode "Html.BeginFormSitefinity". This method has all of the same overrides but doesn't behave in quite the same way - when I attempt to use this code:

Html.BeginFormSitefinity(null, null, FormMethod.Post, new { @action="EXTERNAL_URL" })

This produces the following opening form tag:

<form action="/TestProject/TestPage/Index" method="POST" name="defaultForm" action="EXTERNAL_URL">

As you can see, it's popping a second action attribute in rather than overriding the action attribute as seen in the default MVC method's behaviour.

I'm hoping that someone with a better understanding of how Sitefinity works might be able to provide some advice here?


回答1:


Looking at the sources of the HybridForm, it cannot be modified so it will take action htmlAttribute into account: http://pastebin.com/5dfQdzs8

So you may create your own form based on this code. You'll need html helper:

public static MyHybridForm BeginFormSitefinity(this HtmlHelper htmlHelper, string actionName, string formName, FormMethod method, IDictionary<string, object> htmlAttributes)
{
  return new MyHybridForm(htmlHelper.ViewContext, actionName, formName, method, (object) htmlAttributes);
}

and override GenerateActionUrl() in your MyHybridForm by using action htmlAttribute into account.



来源:https://stackoverflow.com/questions/20413925/sitefinity-cms-html-beginformsitefinity-with-external-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!