0

I use model binding in my application to get the Information from the view to my model class property.
I just want the entered data from my input form in the properties of my model class without rendering the view again.

The binding works, but i dont know what i have to return in the Controller method.


Model class(Events):

public string EventDay { get; set; }


Controller method:

[HttpPost]
public void Search(Events model)
{
    var day = model.EventDay;
}

Html input form:

<form method="post" action="@Url.Action("Search","Book")">
    <div id="select-custom" class="box -custom">
        <label class="select-custom">
            <input class="input-custom" type="date" id="eventDay" name="eventDay" value="dd-mm-yyyy"/>
            <button type="submit" id="Search_reservation" class="button-custom display-none">Search</button>
        </label>
    </div>
</form>
johnwix
  • 1
  • 4
  • You should consider using Ajax calls from view, will this example help? https://stackoverflow.com/questions/16186083/making-a-simple-ajax-call-to-controller-in-asp-net-mvc – Roman Kalinchuk Jun 22 '20 at 12:53

1 Answers1

0

By using an Ajax call you can send the data and also GET data. and also you and set the data in DOM with referencing a page.

also, you can return JSON data using the JsonResult method of MVC.

Here I share some demo ajax call example here

https://www.c-sharpcorner.com/blogs/using-ajax-in-asp-net-mvc

  • Seems ajax is what i am looking for. How would the JavaScript ajax function would look like? I am not really familiar with JavaScript. – johnwix Jun 22 '20 at 14:47
  • $("#Search_reservation").click(function(){ var Events = {EventDay: $('#eventDay').val()}; $.ajax({ type: 'POST', url: '@Url.Action("Search")', dataType: 'json', data: Events, success: function (data) { alert("Datsuccess callback") }, error: function (ex) { } }); } – dhrumil shah Jun 23 '20 at 05:40
  • you can upvote my answer so others and also see the answer if they have the same problem like yours – dhrumil shah Jun 23 '20 at 08:19
  • I did, but i have less then 15 reputation so it wont be displayed unfortunatly – johnwix Jun 23 '20 at 08:33