0

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?

2
  • 1
    Step 1) Post code. Step 2) Explain the problem you are having in detail. Step 3) Vote up and accept and answer if it helps you. Commented Mar 30, 2012 at 14:15
  • add an <input type='button'> in the view, it's still ASP.NET, but forget drag & drop controls on the view, you have to actually code the view. Commented Mar 30, 2012 at 14:16

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.