click on edit button then not open the employee edit page RRS feed

  • Question

  • User-91993069 posted

    I am calling blazor server side getemp webapi in client side

    I have two record in table

    blazor server side getemp web api work fine


    namespace CrudBlazorServerApp.Controllers
        public class EmpsController : ControllerBase
            private readonly sqldbcontext _context;
            public EmpsController(sqldbcontext context)
                _context = context;

    // GET: api/Emps
    public async Task<ActionResult<IEnumerable<Emp>>> Getemps()
    return await _context.emps.ToListAsync();
    } [HttpGet("{id}")] public async Task<ActionResult<Emp>> GetEmp(int id) { var emp = await _context.emps.FindAsync(id); if (emp == null) { return NotFound(); } return emp; }

    I am calling getemp webapi in client side when user click on edit button but editemployee page not open


                @foreach (var emp in empList)
                        <a href='/EditEmployee/@emp.empid'>Edit</a>

    I create a editemployee page in pages folder


    @using CrudBlazorServerApp.Data
    @page "/EditEmployee/empid/"
    @inject HttpClient Http
    @using System.Net.Http
    <h4>Edit Employees</h4>
    <hr />
    <div class="row">
        <div class="col-md-4">
                <div class="form-group">
                    <label for="username" class="control-label">username</label>
                    <input for="username" class="form-control" bind="@emp.username" />
                <div class="form-group">
                    <label asp-for="empaddress" class="control-label">empaddress</label>
                    <input asp-for="empaddress" class="form-control" bind="@emp.empaddress" />
                <div class=" form-group">
                    <label asp-for="password" class="control-label">password</label>
                    <input asp-for="password" class="form-control" bind="@emp.password" />
                <div class=" form-group">
                    <label asp-for="country" class="control-label">country</label>
                    <input asp-for="country" class="form-control" bind="@emp.country" />
                <div class="form-group">
                    <input type="submit" class="btn btn-default" />
    @code {
        Emp emp;
        protected override async Task OnInitializedAsync() =>
            emp = await Http.GetFromJsonAsync<Emp>("https://localhost:44333/api/emps/getemp/" + emp.empid);

    Hierarchy Of Project

    getemp webapi work fine but when I click on edit button then not open the editemployee page

    which place I am doing wrong?

    Saturday, September 5, 2020 7:32 AM

All replies