Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3
I am new to MVC. Hi have done small project. when i click on edit actionlink it should popup i wrote its working fine. when popup displays i changed the data in edit popup when i click on save button. its not disappearing. please help me
here is my code. here i kept editorstemplate one folder in that folder Editinput.cshtml it will display all fields when i click on edit.
Movie Controller.
  public ActionResult Edit(int id)
        {
           
            Movies movies = db.Movies.Find(id);
            return PartialView(movies);
        }
 
        //
        // POST: /Movies/Edit/5

        [HttpPost]
        public ActionResult Edit(Movies movies)
        {
            if (ModelState.IsValid)
            {
                if (Request.IsAjaxRequest())
                {
                    db.Entry(movies).State = EntityState.Modified;
                    db.SaveChanges();
                    return View("Index", movies);
                }
                
               
            }
            return RedirectToAction("Index");    
            
        }
 
in Index.cshtml.
@model IEnumerable<MVCSampleProject.Models.Movies>
 
@{
    ViewBag.Title = "Index";
}
 
<h2>Index</h2>
 
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            Title
        </th>
        <th>
            ReleaseDate
        </th>
        <th>
            Genre
        </th>
        <th>
            Price
        </th>
        <th></th>
    </tr>
 
@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ReleaseDate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Genre)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Price)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.ID }, new { @class="openDialog",data_dialog_id="emailDialog", data_dialog_title="Edit"})
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}
 
</table>
 

in Edit.cshtml.
@model MVCSampleProject.Models.Movies
 

<h2>Edit</h2>
 
@Html.Partial("_Edit")
 
_Edit.cshtml
@model MVCSampleProject.Models.Movies
           
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "emailDialog" }))
{
    @Html.ValidationSummary(true)
    
    @Html.EditorForModel() 
    
    <p>
        <input type="submit" value="Save" />
    </p>
}
 
EditInput.cshtml.cs
@model MVCSampleProject.Models.Movies
<h2>Editinfo</h2>
 
    <fieldset>
        <legend>Movies</legend>
 
        @Html.HiddenFor(model => model.ID)
 
        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>
 
        <div class="editor-label">
            @Html.LabelFor(model => model.ReleaseDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ReleaseDate)
            @Html.ValidationMessageFor(model => model.ReleaseDate)
        </div>
 
        <div class="editor-label">
            @Html.LabelFor(model => model.Genre)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Genre)
            @Html.ValidationMessageFor(model => model.Genre)
        </div>
 
        <div class="editor-label">
            @Html.LabelFor(model => model.Price)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Price)
            @Html.ValidationMessageFor(model => model.Price)
        </div>
 
       
    </fieldset>
}
 
 
here my javascript code
 
<script type="text/javascript">
 
         $.ajaxSetup({ cache: false });
 
         $(document).ready(function () {
             $(".openDialog").live("click", function (e) {
                 e.preventDefault();
 
                 $("<div></div>")
                    .addClass("dialog")
                    .attr("id", $(this)
                    .attr("data-dialog-id"))
                    .appendTo("body")
                    .dialog({
                        title: $(this).attr("data-dialog-title"),
                        close: function () { $(this).remove() },
                        modal: true
                    })
                    .load(this.href);
             });
 
             $(".close").live("click", function (e) {
                 e.preventDefault();
                 $(this).closest(".dialog").dialog("close");
             });
         });
    </script>
 

please help me thank you.
regards
Sreekanth.
Posted 8-Aug-12 21:23pm
sree561.1K

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 590
1 Sergey Alexandrovich Kryukov 467
2 OriginalGriff 285
3 PIEBALDconsult 285
4 BillWoodruff 173


Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 9 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100