0

I build a web site with MVC4, and in my routeConfig file I have this procedure:

Public Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
    routes.IgnoreRoute("{resource}.aspx/{*pathInfo}")
    routes.IgnoreRoute("{resource}.aspx")
    default.aspx will load instead
    routes.MapRoute(
        name:="Default",
        url:="{controller}/{action}/{id}",
        defaults:=New With {.controler = "Home", .action = "Index", .id = UrlParameter.Optional}
    )
End Sub

In my HomeControler I have this function:

Function Index() As ActionResult
    Return View("Default")
End Function

Thus my Default.aspx is working just fine. But.
When I'm trying to click a button cannot Handle the onclick event (never goes to the sub.
So I use a OnClientClick in aspx to raise up this event.
But throws me the error of:

grFlagsBtn_Click' is undefined

And one more issue... I've noticed the program remains on Home/Index environment. Where there is no any Index file at this area.
But the Url in my browser says href="http://localhost:49224/Home/Index"
I found that very much strange, because the program should be in /Home/Default.. I think, I'm not of that.
Please is some one to give me some help on this?

adiga
  • 34,372
  • 9
  • 61
  • 83
Lefteris Gkinis
  • 1,229
  • 6
  • 26
  • 63
  • I'm pretty sure mvc doesn't have server event like onclick it all has to do with the [different route actions](https://stackoverflow.com/questions/16440365/how-to-trigger-button-click-in-mvc-4). – the_lotus Feb 08 '19 at 18:03
  • @ the_lotus So will never be able to handle the `onclick` event which is in asp.net ? – Lefteris Gkinis Feb 08 '19 at 18:05
  • 1
    MVC is radically different in it's way of handling postback compared to winform. Even if both have the acronym ASP.NET in them. – the_lotus Feb 08 '19 at 18:07
  • @ the_lotus I choose MVC for better organize and better work. Now.. I don't know – Lefteris Gkinis Feb 08 '19 at 18:09
  • Don't give up :) MVC has a lot of advantages. A small tutorial should be enough to let you understand how it all works. Just think "In MVC there are no events on controls". – the_lotus Feb 08 '19 at 18:11
  • 2
    Probably have a look at https://stackoverflow.com/q/102558/11683 and https://www.codeproject.com/Articles/575397/An-Absolute-Beginners-Tutorial-on-ASP-NET-MVC-for. – GSerg Feb 08 '19 at 18:12
  • So I think it is an opportunity to work with `Javascript`. And call functions and procedures from this environment. Any Idea ??? – Lefteris Gkinis Feb 08 '19 at 18:17
  • MVC uses helpers to create the HTML code. You can write pure html instead or add the onclick event into the object that runs a javascript to perform a POST/GET. ex: @Html.RadioButton("name", "1", false, new { onclick = "ShowOption(this)", id = p.id }) – Chillzy Feb 08 '19 at 23:36
  • You can also create a form and put your controls in it then change the onclick OR onchange for "$("#myForm").submit();" – Chillzy Feb 09 '19 at 00:21
  • @ Chillzy thank you for your answer. But I decide to approach my issue from another point of view. You see I don't to get reed the ASPX markup page. I have adapted with it very well. Thank you all any way. – Lefteris Gkinis Feb 09 '19 at 10:04
  • This Question has it's answer here [https://stackoverflow.com/questions/54762756/auto-postback-in-mvc4-razor-page] – Lefteris Gkinis Feb 19 '19 at 15:43

0 Answers0