Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:36:13+00:00 2026-06-07T10:36:13+00:00

I have a from and to date search box on my view. This POSTs

  • 0

I have a from and to date search box on my view.

This POSTs to my controller, which then searches for available rooms between the dates selected. The results are then listed in the view again.

I’m used to WebForms, where you can PostBack, and grab any control data – however in MVC you can’t do this.

When the results are displayed, how can I then POST back to a controller, both the RoomId that has been selected:

 @Html.ActionLink("Book Room","Book", new { id=item.RoomId })

…and the tbFrom and tbTo dates from the TextBoxes?

My view is below.

Thanks for any assistance,

Mark

@model IEnumerable<ttp.Models.Room>
@{
ViewBag.Title = "Avail";
}

<h2>Avail</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm())
{
    <p>
        Availability between @Html.TextBox( "dteFrom" , String.Format( "{0:dd/MM/yyyy}", DateTime.Now) , new  { @class = "datepicker span2" } ) 
                         and @Html.TextBox( "dteTo" , String.Format( "{0:dd/MM/yyyy}", DateTime.Now) , new  { @class = "datepicker span2" } )
        <input type="submit" value="Search" /></p>
}
<table class="table table-striped table-bordered table-condensed" style="width:90%" id="indexTable" >
<tr>
    <th>
        @Html.DisplayNameFor(model => model.RoomName)
    </th>
</tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.RoomName)
        </td>
...
...
        <td>
            @Html.ActionLink("Book Room","Book", new { id=item.RoomId }) 
        </td>
    </tr>
}

</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:36:15+00:00Added an answer on June 7, 2026 at 10:36 am

    make your views strongly typed… and to know what strongly typed views are in mvc.net here are a few links

    http://www.howmvcworks.net/OnViews/BuildingAStronglyTypedView

    What is strongly-typed View in ASP.NET MVC

    http://blog.stevensanderson.com/2008/02/21/aspnet-mvc-making-strongly-typed-viewpages-more-easily/

    more over if you have the default routes set in your application, in your POST action result you can get the id as the route value like

    [HttpPost]
    public ActionResult POSTACTION(int id){
     //here you will get the room id 
    }
    

    but from the code what i see is that you are not posting a form, actionlinks make a GET request in that case remove the [HttpPost] action filter from the action result…

    EDIT

    may be i just misunderstood the question… in your current scenario if ajax is an option you can do something like this

    assign a class to your action links like

       @Html.ActionLink("Book Room","Book", new { id=item.RoomId },new{@class="roomclass",id=item.RoomId})
    

    now attach a click event handler to it

    $(function(){
     $(".roomclass").on("click",function(e){
       e.preventDefault(); //prevent the default behaviour of the link 
       var $roomid = $(this).attr("id");//get the room id here 
       //now append the room id using hidden field to the form and post this form 
       //i will assume that you have only one form on the page 
       $("<input/>",{type:'hidden',name="RoomId",value:$roomid}).appendTo("form");
       $("form").submit();   
      });
    });
    

    specify the action name and controller to which the form will be posted

    @using (Html.BeginForm("MyAction","ControllerName",FormMethod.POST)){...}
    

    in your controller you will have something like

    [HttpPost]
    public ActionResult MyAction(int RoomId,DateTime? dteFrom ,DateTime? dteTo ){
     //you will get the form values here along with the room id 
     // i am not sure about the type `DateTime?` parameteres if this doesn't work try using string dteFrom and string dteTo
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a combobox which is displaying date from database...in my database the date
i have a textbox which is filled with date from a datepicker(calendar is accessed
Assume I have these tables, from which i need to display search results in
I want to have search results from SOLR ordered like this: All the documents
I have a VF page which has 2 date fields and search button. On
We have a from date and To date in Table fields. We are getting
I have a value from my database. How do I extract the date from
I have to get a date from a string. So I am using the
We have a function that pulls the date from the first 8 characters of
I have a function that returns a date from a stored procedure, and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.