0

The Ajax form does update selected div, but instead of just reloading a partial view in that div it inserts the whole page content into that div.

.cshtml file

<fieldset>
 <legend>File(s)</legend> 
 <div id="filesBody">
 @Html.Action("Action", "Controller", new {id=Model.Id})
 </div>
 <br />
 @using (Ajax.BeginForm("UploadFile", "Controller", null, new AjaxOptions { UpdateTargetId="filesBody"}, new { enctype = "multipart/form-data", @id = "myForm" }))
 { 
 @Html.HiddenFor(model => model.ComplaintId)
 <div>
 <label for="File">Add File:</label>
 <input type="file" name="FileAttachment" />
 &nbsp;<input type="submit" value="Upload" />
 @Html.ValidationMessage("FileAttachment")
 </div>
 }
</fieldset>

Controller

public PartialViewResult GetFilesData(long? Id)
{
 Model Model = new Model(Id);
 TryUpdateModel(Model);
 return PartialView(Model);
}

Partial view

@model Models
<div id="reloadField">
 @foreach (var ph in Model.docs)
 {
 ///code
 }
</div>
asymptoticFault
4,5392 gold badges21 silver badges25 bronze badges
asked Sep 26, 2013 at 18:28
1
  • Shouldn't your Ajax.BeginForm be targeting the GetFilesData action? Commented Sep 26, 2013 at 18:35

1 Answer 1

3

In your partial view set the Layout equal to null.

@model Models
@{
 Layout = null;
}

UPDATE

Change your Ajax.BeginForm to call the GetFilesData action.

answered Sep 26, 2013 at 18:33

2 Comments

Still inserts whole page into that div
I don't know if the problem still exists, but unobtrusive javascript should be enabled in web.config and jquery.unobtrusive-ajax.js should be referenced on page.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.