"There is one caveat. Since WebForms requires that you only have a single HTML form tag on the page, you cannot use the default@Html.BeginForm helper. We have provided an alternative for you, which you can use
instead. Everywhere that you need to render a form, you can use @Html.BeginSitefinityForm."
I would recommend you to use Sitefinity forums and support system as Sitefinity MVC in Hybrid mode is slightly different than regular MVC and we aren't monitoring asp.net forums for issues regarding Sitefinity :(
jania11
0 Points
5 Posts
MVC ( in Sitefinity)
Dec 29, 2012 02:59 PM|LINK
In my View I have sth like that:
@model CreatorModel
------
<form name="myForm" action="/Creator/CreateAction" enctype="multipart/form-data" id="myForm" method="post">
<div class="a">
<h2 class="a">....</h2>
<div class="b">
<br />
Select a file for a <input type="file" name="aFile" id="aFile" />
<br /><br />
Select a file for b<input type="file" name="bFile" id="bFile" />
<br /><br />
<input type="submit" id="CreateAction" name="CreateAction" value="CreateAction" />
</div>
</form>
-------
But I have an error : File /Creator/CreateAction is not found (CreateAction is an action from CreatorController)
What can I enter as action in <form...> in order to find action from controller?
When I'm using this syntax:
Thanks for help in advance
ignatandrei
All-Star
134820 Points
21598 Posts
Moderator
MVP
Re: MVC ( in Sitefinity)
Dec 29, 2012 03:57 PM|LINK
1.
action='@Url.Content("~/Creator/CreateAction")'
2.
it is different from the first, isn't it?
3
When ? Which line? What's the action?
jania11
0 Points
5 Posts
Re: MVC ( in Sitefinity)
Dec 29, 2012 06:01 PM|LINK
Hi, thanks a lot for the quick response.
When I use this code in my View:
@using (Html.BeginForm(Url.Content("~/Creator/CreateAction"), "ProductsAndDepartmentsCreator", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.TextBoxFor(m => m.RoboticsFile, new { type = "file" })
@Html.TextBoxFor(m => m.MeasurementsFile, new { type = "file" })
<input type="submit" id="CreateAction" name="CreateAction" value="CreateAction" />
}
I have the following error:
Object reference not set to an instance of an object.
stack trace: at Telerik.Sitefinity.Mvc.SitefinityMvcRoute.GenerateVirtualPath(RouteValueDictionary values)
at Telerik.Sitefinity.Mvc.SitefinityMvcRoute.GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
at System.Web.Routing.RouteCollection.GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
at System.Web.Mvc.RouteCollectionExtensions.GetVirtualPathForArea(RouteCollection routes, RequestContext requestContext, String name, RouteValueDictionary values, Boolean& usingAreas)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
at System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, FormMethod method, IDictionary`2 htmlAttributes)
at System.Web.Mvc.Html.FormExtensions.BeginForm(HtmlHelper htmlHelper, String actionName, String controllerName, FormMethod method, Object htmlAttributes)
at ASP._Page_MVC_Views_ProductsAndDepartmentsCreator_Default_cshtml.Execute() in c:\work1\OneABB-WCMS\trunk\Projects\Abb.Portal.Web\Mvc\Views\ProductsAndDepartmentsCreator\Default.cshtml:line 16
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at Telerik.Sitefinity.Mvc.SitefinityActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
CPrakash82
All-Star
18256 Points
2837 Posts
Re: MVC ( in Sitefinity)
Dec 29, 2012 08:11 PM|LINK
Again you changed the syntax completely.
If you want to use BeginForm then you can specify the controller and action directly and url.content is not required.
@using (Html.BeginForm("CreateAction", "Creator", FormMethod.Post, new { enctype = "multipart/form-data" })) { <input type="file" name="RoboticsFile" id="RoboticsFile" /> <input type="file" name="MeasurementsFile" id="MeasurementsFile" /> <input type="submit" /> } public ActionResult CreateAction(HttpPostedFileBase RoboticsFile, HttpPostedFileBase MeasurementsFile) { .....jania11
0 Points
5 Posts
Re: MVC ( in Sitefinity)
Dec 30, 2012 08:37 AM|LINK
Hi again,
Thanks for reply.
I,ve tried to do this in that way, but unfortunately after choosing files and submitting HttpPostedFileBase is always null.
CPrakash82
All-Star
18256 Points
2837 Posts
Re: MVC ( in Sitefinity)
Dec 30, 2012 02:35 PM|LINK
Can you access the file from Request object?
jania11
0 Points
5 Posts
Re: MVC ( in Sitefinity)
Dec 30, 2012 08:01 PM|LINK
Unfortunately not (because Response.Files.Count = 0)
CPrakash82
All-Star
18256 Points
2837 Posts
Re: MVC ( in Sitefinity)
Dec 30, 2012 09:09 PM|LINK
You are looking at the response and not request.
Look at - Request.Files
jania11
0 Points
5 Posts
Re: MVC ( in Sitefinity)
Dec 31, 2012 01:34 PM|LINK
Sorry, I've mistaken in the previous post, Reuest.Files.Count = 0.
When I create a mvc project from scratch all Your solutions works fine. So I think my problem is caused by sitefinity.
Thanks a lot for help.
Stoimen.Stoi...
Member
2 Points
1 Post
Re: MVC ( in Sitefinity)
Jan 03, 2013 08:14 AM|LINK
Hi,
Please have a look at http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/how-does-sitefinity-use-asp.net-mvc/three-mvc-modes/hybrid-mode
And more specifically at these lines:
"There is one caveat. Since WebForms requires that you only have a single HTML form tag on the page, you cannot use the default@Html.BeginForm helper. We have provided an alternative for you, which you can use instead. Everywhere that you need to render a form, you can use @Html.BeginSitefinityForm."
I would recommend you to use Sitefinity forums and support system as Sitefinity MVC in Hybrid mode is slightly different than regular MVC and we aren't monitoring asp.net forums for issues regarding Sitefinity :(