views:

496

answers:

3

I'm currently in the process of learning ASP MVC and am running into a few issues.

First, when I use

<%=Http.ActionLink("Add / Modify", "AddModify" %>

it will show as Add / Modify (/Home/AddModify) in Firefox and Add / Modify in IE. It is doing that to all links in FF and none in IE. Anyone know what reasoning is for that?

Edit: What is displayed in the browser (FF in this case) is "Add / Modify (/Home/AddModify)" while in IE shows just "Add / Modify".
Here is a screenshot of what I see on my site in FireFox: http://img6.imageshack.us/img6/1331/19748435.png

You can see how it shows the text and the appropriate link afterwards (only populated in Database with /).

Also, I am trying to have buttons (both standard and image) on my site which will link to new pages, while also performing hidden tasks (saving data, etc...). Anyways, When I do the following:

<form method="post" action="/Home">
    <input type="submit" value="AddModify">
</form>

and the controller has a simple

[ActionVerbs(HttpVerbs.Post)]
public ActionResult AddModify()
{
    return View();
}

And I still cannot get that function to call, yet when I do http://localhost:port/Home/AddModify, the function calls and I can get to that page. I am doing it this way because there may be code that has to execute before redirecting to that page, rather than just a direct link to that page. I have tried with and without the ActionVerbs line, I have tried this form of the Html Form:

<% using (Html.BeginForm()) { %> ... <%}%>

and still nothing. I have also tried no form and still nothing, but here's something that may affect this...I am using a master page with everything inside a content place holder inside a form that uses runat="server". Would that matter? So its Master Page -> form (masterform runat server) -> ContentPlaceHolder -> form (for postback and action) -> submit button. Any help would be greatly appreciated.

+1  A: 

If I am thinking correctly, your form action should be calling the name of the action method:

<form method="post" action="/Home/AddModify">
    <input type="submit" value="AddModify">
</form>

The ActionLink would be the same way.

Otherwise you will need to modify your routes to go to that action method by default.

mc2thaH
I tried that too. No success.
dangerisgo
Then you will need to modify your routes to point to that action method by default.
mc2thaH
A: 

<form method="post" action="/Home">

Will create a form with a href of /Home, this will only call the AddModify action if the AddModify action is default on that route.

Richard
A: 

Let's do this in two parts

1 I think your ActionLink should be:

<%=Http.ActionLink("Add / Modify", "AddModify", "Home")

...to force routes.

First parameter: text shown Second parameter: action name Third parameter: controller name

2 Change your submit button to: (I assume we're currently looking at your "index" action from your "Home" controller)

<form method="post" action="/Home">
    <input type="submit" value="AddModify" name="ModifyBtn" >
</form>

Then in your Home controller:

edit:

//GET
public ActionResult Index()
{
    return View();
}

/edit

[ActionVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection form, string ModifyBtn, string OtherBtn)
{
   if (ModifyBtn!=null)
   {
      //do stuff
      return RedirectToAction("AddModify");
   }

   if (OtherBtn!=null)
   {
      //do stuff
      return RedirectToAction("OtherAction");
   }

return View();
}

edit: I think you're trying to submit directly to another Action. The best way is to handle the POST method inside your code then redirect to another action. That way, you can use

<% using (Html.BeginForm()) { %>

without trouble.

Francisco
Thanks, but I cannot access 'ModifyBtn' from the controller. Also, doesn't this defeat the whole purpose of having each control call its own function? Just seems counter intuitive.
dangerisgo
It is... but what can I say? I had a lot of trouble getting used to handling code flow in MVC.
Francisco
Thank you. That seemed to work. Now what if I wanted to do it with an image instead? Is that possible?
dangerisgo
N/m, got it to work with am image, but that firefox issue still remains.
dangerisgo
I can't seem to replicate the issue in my FF. In both cases it displays the correct text and the correct link.Text being "Add / Modify" and link being "localhost/Home/AddModify.aspx" which is what it would normally do.
Francisco
Francisco, here is a screenshot of what I see in firefox: http://img6.imageshack.us/img6/1331/19748435.png Its the title bar on my website.
dangerisgo
It would be more useful to have the HTML rendered to see what's really going on. But anyways... I don't think I have an answer to that =( Sorry. My guess would be a compatibility issue with an uncommon version of firefox or maybe an addon problem.
Francisco
I disabled all my addons and I'm using FF 3.5. Still shows those parentheses. I am using firebug and probed those links and just see the following:<li><a href="">Documentation</a>exactly as i see in the HTML in the source.
dangerisgo
Try to reload the page with CTRL+F5Firefox sometimes gives me problems when I change CSS and what not
Francisco