2

AFAIK, the Asp.net Web Pages model only supports a single form post per page. The user input is taken in with:

if (isPost)
{
   // code to capture form input
}

However, is it possible to have Asp.net Web Pages behave more like Rails in allowing multiple actions (methods) per page?

I would like to be able to have a user click a button (posting to the same page) which deletes a given record in a db and then refreshes the same page.

Jason
  • 1,129
  • 1
  • 9
  • 20
  • You've asked a question about ASP.NET MVC 3 *a month ago*, yet your asking a question like this? Unless i'm totally confused by your question. – RPM1984 Oct 06 '11 at 05:08

3 Answers3

8

Take a look at ASP.NET MVC.

2

Your premise that the Asp.Net Web Pages model only supports a single form post per page is incorrect. You can have multiple forms. Rather than using the simple IsPost test, you provide a different name attribute to each form's associated submit button, and test to see which one was clicked by examining the Request.Form collection:

@{
  if(Request["form1"] == "submit"){
    //form1 submitted
  }
  if(Request["form2"] == "submit"){
    //form2 submitted
  }
}
...

<form method="post" id="form1">
  ...
  ...
  <input type="submit" name="form1" value="Submit" />
</form>

<form method="post" id="form2">
  ...
  ...
  <input type="submit" name="form2" value="Submit" />
</form>

But if you want an MVC framework, as others have said, use ASP.NET MVC.

Mike Brind
  • 28,238
  • 6
  • 56
  • 88
1

You can use jQuery and ASP.NET Page Methods to post a request to the server that calls a delete function.

You can use jQuery to post a form with an action attribute that points to delete function. Here is a great code sample to demonstrate something similar. (That example shows an insert, not a delete.) There's another reference to that same example here on SO.

I should add that this answer is meant to complement Mike Brind's answer, which I have upvoted.

Community
  • 1
  • 1
bflow1
  • 969
  • 1
  • 10
  • 25
  • I was thinking Web Forms. I'll delete my answer. I couldn't find anything about Web Pages and Page Methods anywhere in the MSDN docs. – bflow1 Oct 06 '11 at 15:41