Results 1 to 9 of 9

Thread: How to pass value of lastrecord from controller to view when click on last button

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    How to pass value of lastrecord from controller to view when click on last button

    problem
    How to pass value of last record from controller to view when click on last button .

    I have controller employee have action create

    In this action create I have view for create action

    on view create i have button Last

    this button when i press on it i need it get last record

    if table employee have employeeid from 1 to 5 and click on last button it must go to record 5 and show it
    so that what i do as below

    Code:
     public IActionResult Create()
            {
         
                 var results = _context.GetAll().OrderBy(Employee => Employee.EmployeeId).LastOrDefault();
              
                return View();
            }
    
     [HttpPost]
            [ValidateAntiForgeryToken]
            public async Task<IActionResult> Create(Employee employee)
            {
            }
    on view create 
    <div class="title_of_div">
        <button id="BtnLast" style="display: inline"><b>Last</b></button>
    </div>
    <div class="row">
        <div class="col-md-4">
            <form asp-action="Create">
    
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                <div class="form-group">
                    <label asp-for="EmployeeId" class="control-label"></label>
                    <input asp-for="EmployeeId" class="form-control" />
                    <span asp-validation-for="EmployeeId" class="text-danger"></span>
                </div>
              
                <div class="form-group">
                    <label asp-for="EmployeeName" class="control-label"></label>
                    <input asp-for="EmployeeName" class="form-control" />
                    <span asp-validation-for="EmployeeName" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="EmployeeAge" class="control-label"></label>
                    <input asp-for="EmployeeAge" class="form-control" />
                    <span asp-validation-for="EmployeeAge" class="text-danger"></span>
                </div>
             
                <div class="form-group">
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </form>
        </div>
    </div>

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to pass value of lastrecord from controller to view when click on last button

    I don't really know what question you're asking.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to pass value of lastrecord from controller to view when click on last button

    Thank you for reply actually I have button name Last I need when click on it get last record for employee
    so that what function i will write
    and in whuch place action get or post
    and whati write on view
    can you help me in that please

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to pass value of lastrecord from controller to view when click on last button

    Thank you for reply
    actually I have button name Last I need when click on it get last record for employee table and show it
    so that what function i will write to get last ?
    and in which place action get or post i will put this
    and what i write on view ?
    can you help me in that please if possible

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to pass value of lastrecord from controller to view when click on last button

    You already know how to get the last record because you're already doing it. Put that code in an action and call that action from the Last button. That's all there is to it.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to pass value of lastrecord from controller to view when click on last button

    thank you for reply
    how to call action from last button view if possible can you tell me

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to pass value of lastrecord from controller to view when click on last button

    thank you for reply
    how to call action from last button view if possible can you tell me

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to pass value of lastrecord from controller to view when click on last button

    What do you not understand about the information you found when you searched the web on that subject?

  9. #9
    Member
    Join Date
    Jul 2019
    Location
    Ahmedabad
    Posts
    57

    Re: How to pass value of lastrecord from controller to view when click on last button

    Try using onclick this way::

    Code:
    <div class="title_of_div">
        <input type="button" value="Last" id="BtnLast" style="display: inline" onclick="location.href='@Url.Action("Action","Controller")'"/>
    </div>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width