PDA

View Full Version : [CLOSED] Login MVC application



romeu
Apr 25, 2012, 6:37 PM
Hi,

We are trying to migrate from Ext.NET 1.2 to 2.0. After several adjustments, we stopped on this issue.
When the user posts a login form to the server, the textfield values are not passed to our method on the controller. We get null on our arguments txtUsername and txtPassword.


Can you send me the MVC Application Demo ?


Regards

Daniil
Apr 25, 2012, 8:39 PM
Hi,



Can you send me the MVC Application Demo ?

It has been not ported to Ext.NET v2 yet.


When the user posts a login form to the server, the textfield values are not passed to our method on the controller. We get null on our arguments txtUsername and txtPassword.

Can you provide a sample to reproduce?

romeu
Apr 26, 2012, 1:14 PM
This is the Controller code:

[AcceptVerbs(HttpVerbs.Post)]
[HttpPost]
public ActionResult Login(string txtUsername, string txtPassword)
{
if (!ValidateLogOn(txtUsername, txtPassword))
{
return new AjaxResult { ErrorMessage = "Usuário ou Senha incorretos." };
}

this.FormsAuth.SignIn(txtUsername, true);

return this.RedirectToAction("Index", "Home");
}

And this is the view code:

<ext:Window ID="LoginWindow" runat="server" Closable="false" Resizable="false" Height="130"
Icon="Lock" Title="Usuário/Senha" Draggable="true" Width="300" Modal="true" Layout="fit"
Padding="5">
<Items>
<ext:FormPanel ButtonAlign="Center" runat="server" FormID="form1" Border="false"
ShowOnLoad="true" Layout="form" BodyStyle="background:transparent;" Url='<%# Html.AttributeEncode(Url.Action("Login")) %>'>
<Items>
<ext:TextField ID="txtUsername" Name="txtUsername" runat="server" FieldLabel="Usuário"
AllowBlank="false" BlankText="Usuário é obrigatório." Text="Adm" AnchorHorizontal="100%" />
<ext:TextField ID="txtPassword" runat="server" InputType="Password" FieldLabel="Senha"
AllowBlank="false" BlankText="Senha é obrigatória." Text="123456" Name="txtPassword" AnchorHorizontal="100%" />
</Items>
</ext:FormPanel>
</Items>
<Buttons>
<ext:Button runat="server" ID="button_login" Text="Entrar" Icon="Accept">
<DirectEvents>
<Click Url="~/Account/Login" Timeout="60000" FormID="form1" CleanRequest="true"
Method="POST" Before="Ext.Msg.wait('Verificando...', 'Autenticação');" Failure="Ext.Msg.show({
title: 'Erro na Autenticação',
msg: result.errorMessage,
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});">
<EventMask MinDelay="250" />
<%-- <ExtraParams>
<ext:Parameter Name="ReturnUrl" Value="Ext.urlDecode(String(document.location).split('?')[1]).r || '/'" Mode="Raw" />
</ExtraParams>--%>
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:Window>

Vladimir
Apr 26, 2012, 6:11 PM
Hi,

By default, FormPanel doesn't render html form
Please add the following code to the form panel


<AutoEl Tag="Form" />

MarzioPat
May 13, 2013, 9:59 AM
Hi,
I have the same issue, I added the AutoEl but this doesn't fix... Do you you have other suggestion?

Vladimir
May 13, 2013, 10:03 AM
Please post test sample

MarzioPat
May 13, 2013, 11:57 AM
This is my LogOn code


<body>
<ext:ResourceManager ID="MainScriptManager" runat="server" />

<ext:Window
ID="LogOnWindow"
runat="server"
Closable="false"
Resizable="false"
Height="150"
Icon="Lock"
Title="MyApp - Logon"
Draggable="true"
Width="300"
Modal="true"
Layout="FitLayout"
BodyStyle="padding:17px 15px 17px 15px;"
ButtonAlign="Center">
<Items>
<ext:FormPanel
runat="server"
DefaultButton="btnLogOn"
DefaultButtonStopEvent="true"
FormID="formLogOn"
Border="false"
Layout="FormLayout"
BodyStyle="background:transparent;"
Url='<%# Html.AttributeEncode(Url.Action("LogOn")) %>'>


<AutoEl Tag="Form" />

<Items>

<ext:TextField
ID="txtUsername"
runat="server"
AutoFocus="true"
AutoFocusDelay="150"
FieldLabel="Nome Utente"
AllowBlank="false"
BlankText="Nome Utente obbligatorio."
AnchorHorizontal="100%" />

<ext:TextField
ID="txtPassword"
runat="server"
InputType="Password"
FieldLabel="Password"
AllowBlank="false"
BlankText="Password obbligatoria."
AnchorHorizontal="100%" />
</Items>
</ext:FormPanel>
</Items>
<Buttons>
<ext:Button ID="btnLogOn" runat="server" Text="Logon" Icon="Accept">
<DirectEvents>
<Click
Url="~/Account/LogOn/"
Timeout="10000"
FormID="formLogOn"
CleanRequest="true"
Method="POST"
Before="Ext.Msg.wait('Autenticazione in corso...', 'Logon');"
Failure="Ext.Msg.show({
title: 'Errore in fase di Logon',
msg: result.errorMessage,
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR,
fn: function(btn) { #{txtUsername}.focus(false, 100); }
})">
<EventMask MinDelay="250" />


</Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="btnCancel" runat="server" Text="Annulla" Icon="Decline">
<Listeners>


<Click Handler="#{LogOnWindow}.hide();" />
</Listeners>
</ext:Button>

</Buttons>

</ext:Window>

This is my AccountController Code




...
[HttpPost]
[UserHostAddress]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
Justification = "Needs to take same parameter type as Controller.Redirect()")]
public ActionResult LogOn(string txtUsername, string txtPassword, /* string returnUrl, */ string userHostAddress)
{
string licenseError = null;
if (!Core.LicenseHelper.CheckLicense(out licenseError))
{
return new AjaxResult { ErrorMessage = licenseError };
}
...
}

...


The issue is that txtUserName and txtPassword are always null when passed into Controller.

Update: Please look also at the runtime generated code... Ext Net 1.x makes different html code...

MarzioPat
May 13, 2013, 3:26 PM
Okay, I got it moving AutoEl outside the FormPanel!



<ext:Window
ID="LogOnWindow"
runat="server"
Closable="false"
Resizable="false"
Height="150"
Icon="Lock"
Title="MyApp - Logon"
Draggable="true"
Width="300"
Modal="true"
Layout="FitLayout"
BodyStyle="padding:17px 15px 17px 15px;"
ButtonAlign="Center">

<AutoEl Tag="Form" />

<Items>
<ext:FormPanel
runat="server"
DefaultButton="btnLogOn"
DefaultButtonStopEvent="true"
FormID="formLogOn"
Border="false"
Layout="FormLayout"
BodyStyle="background:transparent;"
Url='<%# Html.AttributeEncode(Url.Action("LogOn")) %>'>

<Items>

<ext:TextField
ID="txtUsername"
runat="server"
AutoFocus="true"
AutoFocusDelay="150"
FieldLabel="Nome Utente"
AllowBlank="false"
BlankText="Nome Utente obbligatorio."
AnchorHorizontal="100%" />

<ext:TextField
ID="txtPassword"
runat="server"
InputType="Password"
FieldLabel="Password"
AllowBlank="false"
BlankText="Password obbligatoria."
AnchorHorizontal="100%" />
</Items>
</ext:FormPanel>
</Items>

Daniil
May 13, 2013, 4:49 PM
Hi @MarzioPat,

AutoEl should not be required at all.

MarzioPat
May 14, 2013, 7:16 AM
Hi @MarzioPat,

AutoEl should not be required at all.

Okay, so why removing it from my .aspx page the generated HTML code is different (as you can see in my previous attachment) and the txtUserName and txtPassword are not properly passed into Controller?

I am migrating from 1.x to 2.x and I downloaded 2.x from Ext .Net web site then I am following the CHANGELOG.

Daniil
May 14, 2013, 1:39 PM
Please remove

FormID="formLogOn"
of the FormPanel. There is no such a property anymore.

I added a new breaking change item.

174. The FormPanel's FormID property has been removed. It is not required anymore since a FormPanel doesn't render a form HTML element anymore.
It creates a form element only if needed. To refer a FormPanel, for example, in a DirectEvent's FormID, please use a FormPanel's ID.

So, please set up

ID="FormPanel1"
for the FormPanel and

FormID="FormPanel1"
for the Click DirectEvent.