hasan.iqbal.anik
hasan.iqbal.anik

Reputation: 21

How can I update a model in the view with ajax?

Here is a portion of my code:

@foreach (var item in Model) {

<div class="ticket-overview">
    <ul>
     <li class="ticket-data-activity">
                <a href="#" class="ticket-open-details">
          @{
             String desc = item.Description.ToString();
           if (desc.Length > 20)
                       {
              desc = desc.Substring(0, 20);
                        }
                        @desc
                    }
                 </a>
</li>

I have this view which shows a model from a controller. Now I want to update that model with a ajax call. The view would remain the same, just the model should change.

Is it possible? If yes, how? Give me some idea. Ask if any clarification of the question is needed, as I'm a new user and not an expert in asking.

clarification: It's actually an unordered list which is built like a custom table. Say, I want to go the next page, so I've a button to be clicked on. Then the table data should be updated. Hence the model needs to be updated.

Thanks...

Upvotes: 1

Views: 1392

Answers (1)

Adam Tuliper
Adam Tuliper

Reputation: 30162

Define a div to update. USe jQuery directly via .get() or .ajax(), or Ajax.BeginForm to call a controller See: Using Ajax.BeginForm with ASP.NET MVC 3 Razor

Upvotes: 1

Related Questions