Double "action" in form's View in ASP.NET MVC

L

Luigi

Hi all,
in an ASP.NET MVC application, I need to have 2 possible "action" for my
form's view

<form id="myForm" action="...">
.....
</form>


depends on which button is pushed by the user.
With first button the action has to reload the same view, and with the other
has to pass to the following view.

How can I accomplish this?

Thanks a lot.

Luis
 
L

Luigi

Mark Rae said:
Use two <asp:Button /> webcontrols with the same OnCommand method, but give
them different CommandArgument properties:
http://www.google.co.uk/search?sour...3GB323&q=asp:Button+OnCommand+CommandArgument

Then branch accordingly:

<asp:Button ID="MyButton1" runat="server" Text="Button1"
OnCommand="MyButton_Command" CommandArgument="1" />
<asp:Button ID="MyButton2" runat="server" Text="Button2"
OnCommand="MyButton_Command" CommandArgument="2" />

protected void lnkEvent_Command(object sender, CommandEventArgs e)
{
if (e.CommandArgument.ToString() == "1") // MyButton1 was pushed
{

}
else
{

}
}

What is "lnkEvent_Command" Mark?
Has to be the name of the onCommand parameter?

Luis
 
L

Luigi

Another problem, and how can I "set" the Action value of the form in the IF
clause?

L
 
L

Luigi

Hi Mark, is it possible to use only HTML controls, like

<input type="button" value="Continue"

or

<input type="submit" value="Continua"

instead of Web Controls?

Luis
 
L

Luigi

In my .ascx ASP.NET MVC View I have a form:

<form id="myForm" name="myForm" action="" method="post">

....some textbox controls


<input type="submit" id="add" name="add" value="Add Data" />

<input type="submit" id="submitButton" name="submitButton" value="Continue" />


</form>


My problem is to have 2 different action - so to post to 2 different views -
second which button is clicked, and be able to get the controls values.


L
 
L

Luigi

Ok Mark, you're right.
But in the

if (e.CommandArgument.ToString() == "1")
{
// Adding
}
else
{
// Continue
}

how can I pass the values from the first page and the second page (in the
Else)?

Luis
 
L

Luigi

I hate ASP.NET MVC.....you can not make the normal things that happen in
ASP.NET Web Forms.

L
 
D

David Jackson

I hate ASP.NET MVC.....you can not make the normal things that happen in
ASP.NET Web Forms.

Why are you using it if you hate it so much? Is someone holding a gun to
your head?
 
D

David Jackson

Because I *must* use .ascx pages (the PM order them), with no
code-behind,

That is one of the stupidest things I've heard in a long time!

How can you take someone like that seriously?

Time to look for another job?
 
L

Luigi

David Jackson said:
That is one of the stupidest things I've heard in a long time!

How can you take someone like that seriously?

Time to look for another job?

The entire application - ASP.NET MVC type - has many .ascx pages, with no
code-behind, and *only* HTML controls (like <input type=etc....), and I have
to accomplish this issue following this structure.
Poor me....

Luis
 
J

Juan T. Llibre

re:
!>> That is one of the stupidest things I've heard in a long time!
!>> How can you take someone like that seriously?

Not at all.

You can do anything, in inline code, that you can do in code-behind.
A good programmer needs to be able to program both inline and in code-behind.

re:
!> I have to accomplish this issue following this structure.

There's nothing stopping you.
You can do everything you need to do using inline code.

re:
!> Poor me....

Only if you let uninformed opinions, like David's, influence your decision.

Go ahead and program the ascx pages with inline code.
You can do that in a very productive manner.




===============
 
D

David Jackson

The entire application - ASP.NET MVC type - has many .ascx pages, with no
code-behind, and *only* HTML controls (like <input type=etc....)

An ASP.NET app which is not permitted to use webcontrols is plain
ridiculous!

Why are you even bothering to use ASP.NET in the first place? Why not just
use ASP Classic?
 
J

Juan T. Llibre

re:
!> An ASP.NET app which is not permitted to use webcontrols is plain ridiculous!

ASP.NET, using MVC, can use web controls.

You need to understand what MVC is...and why its web controls are programmed differently.

ASP.NET MVC has the HtmlHelper object which is a property available on every WebControl.
You can call its extension methods to create the intended html string.

The result is a string rendered to the view.

Educate yourself about MVC web controls at :
http://www.codeproject.com/KB/applications/catharsis_part12.aspx

There's a complete MVC project, with sample MVC code, available at CodePlex :
http://www.codeplex.com/Catharsis/

Feel free to read the other 12 articles of that series on MVC's Web Access layer.

Notice this in the description :
"powerful WebControls for large reuse and quick development"

re:
!> Why are you even bothering to use ASP.NET in the first place?
!> Why not just use ASP Classic?

Because ASP.NET has more than 3 times the throughput of "ASP Classic" ?




===============
 
D

David Jackson

!> An ASP.NET app which is not permitted to use webcontrols is plain
ridiculous!

ASP.NET, using MVC, can use web controls.

I know that, Juan, but Luigi isn't permitted to use them because of the
ridiculous restriction imposed upon him by his project manager.
You need to understand what MVC is...

Maybe you should have read the entire thread.
 
J

Juan T. Llibre

re:
!> Maybe you should have read the entire thread.

I did, but the restriction imposed on him is to
not use code-behind, not to use code at all.

He can, perfectly well, use inline code to do what must be done.
That works around the restriction on code-behind imposed on him.




===============
 
D

David Jackson

re:
!> Maybe you should have read the entire thread.

I did, but the restriction imposed on him is to
not use code-behind, not to use code at all.

You must have forgotten the post which included:

"The entire application - ASP.NET MVC type - has many .ascx pages, with no
code-behind, and *only* HTML controls (like <input type=etc....), and I have
to accomplish this issue following this structure."

Do you not consider that restricting an ASP.NET app (MVC or otherwise) to
using only HTML controls is ridiculous?
 
J

Juan T. Llibre

re:
!> "The entire application - ASP.NET MVC type - has many .ascx pages,
!> with no code-behind, and *only* HTML controls (like <input type=etc....)
!> Do you not consider that restricting an ASP.NET app
!> (MVC or otherwise) to using only HTML controls is ridiculous?

Just because there are no web controls used, so far, doesn't meant they can't be used.




===============
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top