2

I am trying to call Controller method from a Button in view.

Controller:

public ActionResult DownloadTemplate()
{       
    return View("DownloadTemplate");
}

[HttpPost]
public ActionResult onclick()
{
    Console.WriteLine("clicked");
    return View();
}

View:

<td class="rightalign">
   <span class="leftalign">                               
        @(Html.Kendo().Button()
          .Name("btnBlankTemplate")
          .HtmlAttributes(new { type = "button", @class = "k-primary" })
          .Content("Blank Template"))
   </span>

How can i Simply call the onclick() method by clicking the view button?

If Kendo MVC is not supporting how can I use simple Button?

2
  • you can use javascript for this Commented Jun 23, 2015 at 4:17
  • Is this a MVC form that is filled out. The methods in your controller that have a corresponding view are called actions and can be called Commented Jun 23, 2015 at 4:46

3 Answers 3

1

The below should work.

                         @(Html.Kendo().Button()
                         .Name("btnBlankTemplate")
                         .HtmlAttributes(new { type = "button", @class = "k-primary" })
                         .Content("Blank Template"))
                         .onclick(ev => ev.Click("onClick")))

refer to the kendo ui documentation here

http://demos.telerik.com/aspnet-mvc/button/events

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

1 Comment

I am using the Events. And giving the Url in JavaScript. Still not working. can you let me know what to include in the JavaScript.
1

I just added below and it is working.

Controller:

[HttpPost]
public ActionResult BlankTemplate()
{
    Console.WriteLine("clicked");
    return View();
}

view :

<script>
    BlankTemplate = function () {            
            $.ajax({
                url: _rootUrl + "Controller/BlankTemplate",
                data: {                   
                },
                type: "POST"
            });
        }
</script>

<span class="leftalign">
<input type="button" id="btnBlankTemplate" class="k-button" value="Blank Template" onclick="BlankTemplate();" />
</span>

Comments

0

If you dont want to use Ajax and simply pass the value using Html.beginform().

controller:

public ActionResult DownloadTemplate()
{
  //To Do
}

View:
@using (Html.BeginForm("DownloadTemplate", "Controller", FormMethod.Post}))
    {
       <span class="leftalign">
       <input type="submit" id="btnBlankTemplate" class="k-button" value="Blank Template"/>
      </span>
    }

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.