0

in my view:

 <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>

    <script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>

    <script src="../../jquery-1.4.1-min.js" type="text/javascript"></script>

 <%= Ajax.ActionLink("Update", "Index", "Home", new AjaxOptions { UpdateTargetId = "time" })%>
        <br />
        <div id="time">
            <% Html.RenderPartial("TimeControl"); %>
        </div>

in my controller:

[HttpGet]
        public ActionResult Index()
        {
            HomeModel model = new HomeModel(Request.Url.Host);

            // Normal Request
            if (!Request.IsAjaxRequest())
            {
                return View("Index", model);
            }

            // Ajax Request
            return PartialView("TimeControl");
        }

in my model:

public HomeModel()
        {
 Time = DateTime.Now;
        }

i think everything is ok, but if iam clicking update link, time will be not updated.. why? it schould be actual if i click update link

1
  • Have you tried using a different ActionResult with a [HttpPost] filter for your ajax call? Commented Jan 14, 2011 at 15:07

3 Answers 3

1

I suggest you do the following:

[HttpGet]
    public ActionResult Index()
    {
        HomeModel model = new HomeModel(Request.Url.Host);

        return View("Index", model);
    }


[HttpPost]
public ActionResult Index()
    {
        HomeModel model = new HomeModel(Request.Url.Host);

           // Ajax Request
        return PartialView("TimeControl");
    }

I think the problem might be that the AJAX request is a POST.

Sign up to request clarification or add additional context in comments.

Comments

0

You may simply try to (1) remove [HttpGet] or (2) set the HttpMethod in the AjaxOptions to "GET".

Ajax.ActionLink("Update", "Index", "Home", new AjaxOptions { UpdateTargetId = "time", HttpMethod = "get" })

That should solve the problem.

(3) If it doesn't, check if you are using the correct overload. This should work:

Ajax.ActionLink("Update", "Index", "Home", null, new AjaxOptions { UpdateTargetId = "time" }), null)

Comments

0

Any of the options in my previous answers could solve your problem if the AJAX isn't working correctly with your application.

Buy in your example, you're also using something that wasn't quite clear to me.

You use a constructor overload that takes the url. And you use the default constructor to set the time. Is the constructor you use (the one that takes the url) also calling the parameterless constructor?

That constructor should do something like this:

public HomeModel(paramter.......) : this()
{
   // Whatever...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.