سؤال

I'm trying to implement a little ajax using unobtrusive ajax of mvc 3. Here is the code snippet:

Controller:

[HttpGet]
    public ActionResult ViewEmployee()
    {
        return View();
    }

    [HttpPost]
    public ActionResult ViewEmployee(EMPLOYEE model)
    {
        var obj = new EmployeeService();
        var result=obj.FindEmployee(model);

        return View("ViewEmployee", result);


    }

View:

  @{AjaxOptions AjaxOpts = new AjaxOptions { UpdateTargetId = "ajax", HttpMethod = "Post" };}

@using (Ajax.BeginForm("ViewEmployee", "Home", AjaxOpts))
{
    @Html.LabelFor(x => x.EmployeeID)
    @Html.TextBoxFor(x => x.EmployeeID)
    <input type="submit" name="Find Name" value="Find Name" />      
}


<div id="ajax">
    @{
        if (Model != null)
        {
            foreach (var x in Model.EmployeeName)
            {
        @x
            }


        }

        else
        {
            @Html.Label("No Employee is selected!")
        }
    }

</div>

I debugged the code, its sending the employee id to the ViewEmployee method, finding the name but not being able to display the name back into the view.

I've activated the unobtrusive ajax property in web.config & imported the scripts into the view.

Whats going wrong with this? Please help.

هل كانت مفيدة؟

المحلول

This is simple but effective article, ask me if you have any more question! I resolved the problem! By the way, whats wrong with stackoverflow, i'm not getting no response literally!

http://www.c-sharpcorner.com/UploadFile/specialhost/using-unobtrusive-ajax-forms-in-Asp-Net-mvc3/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top