Tom Kealy
Tom Kealy

Reputation: 2669

adding a button to a c# mvc project

I've created a simple .NET MVC project, following the walkthrougth on MSDN.com.

I'm confused about how I'd go about adding a button to the page, so that I can map an action to it.

I've tried searching the web for this, but haven't found what I'm looking for.

Does anyone know of any resources that could help me?

EDIT

The JS for the search bar is below.

<script type="text/javascript">
    $(function () {
    $('#search').MyApp('init');
    $('#search').bind('selectItem', function (event, target) {
        alert($(target).attr('data'));
    });

    //        $.getJSON("http://localhost", {},
    //                function (x) {
    //                    //                    var x = [1, 2, 3];
    //                    alert("test");
    //                });

    //        alert('here')
});
</script>

Wha do I need to do to add a search button you can click?

Upvotes: 0

Views: 5535

Answers (3)

mattematico
mattematico

Reputation: 669

you can it like this..

in your razor view

@using(Html.Beginform("action", "controller")){
//insert some form
    <input type="submit" value="OK" />}

and in your controller you must define a action with that actionname that makes the logic

Upvotes: 4

mgnoonan
mgnoonan

Reputation: 7200

You can find a lot of helpful tutorials and videos on the ASP.NET web site.

Upvotes: 1

Yoeri
Yoeri

Reputation: 2249

You cannot map an action directly to a button. You can however determine in the controller which button made a submit call.

2 other options:

  1. Write some javascript to perform the method call for you
  2. Make a URL and style it as a button (by far the easiest method if you don't need to post data)

Upvotes: 0

Related Questions