3

i'm creating a web application with asp.net mvc and struggling with a redirect to a mobile view after pushing a login button. i isolated the problem from the case and created a dummy controller and view

Controller:

public class DummyController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult foo()
    {
        return RedirectToAction("index", "home");
    }

    public void bar()
    {
        Response.Redirect("/home/index");
    }
}

View:

<div>
    <a href="/dummy/foo"><button>redirect to action</button></a>
</div>
<div>
    <a href="/dummy/bar"><button>response redirect</button></a>
</div>

by pushing the first button (foo method) from a mobile devices the redirect does nothing pushing the second button (bar method) the redirect works fine and delivers the expected mobile site (Index.mobile.cshtml)

is there anything i have to keep in mind when using "RedirectToAction" and mobile views?

Dom
  • 31
  • 2
  • Does the Home controller have the Index action? or you want to redirect them to index action in dummy controller? `RedirectToAction` definition `RedirectToAction('Actionname','ctrl name')`. – Karthik Bammidi Sep 16 '13 at 12:26
  • of course the home controller has the index action. the web applicatation works very well in a desktop browser. the described issue only occure with mobile devices – Dom Sep 16 '13 at 12:38
  • 1
    It's just a guess but maybe there is no request made when you load the page in your mobile, because according to this answer http://stackoverflow.com/questions/6393827/can-i-nest-a-button-element-inside-an-a-using-html5 nesting a button inside an a isn't "valid" html. Try removing the button and see if it works. – miensol Oct 30 '13 at 11:13

1 Answers1

0

Having a button inside and anchor is invalid HTML and as far as I know so is putting an anchor inside a button, this could be why you're seeing random behaviour. You could just have an anchor and style it like a button.

Found this http://codepen.io/lukeocom/pen/LpdKz

Buttons are normally meant to go inside forms.

matt_lethargic
  • 2,706
  • 1
  • 18
  • 33