Return A Partial View In JSON From A Controller In MVC?

Mar 16, 2011

I have a list of items(surveys) displayed on my home page. When I click the edit button for a particular item I have a modal pop up with the items details to edit. When the user clicks Save I submit the form via ajax. Depending on whether ModelState.IsValid == true I want to update the modal with validation information or close the modal and update the list of items with the new information.

This is how I am submitting the form:

[Code]...

My Questions

The only thing I can think to do is return JSON from my controller with a flag indicating the state of the ModelState.IsValid and the corresponding partial that I should show.

1) How would I do this?

2) Is there a better way?

Update

I found this: [URL]

but it seems more likely that I am going about the whole thing incorrectly.

View 3 Replies


Similar Messages:

How To Return A Partial View From A Controller With Different Model

Mar 18, 2011

returning a partial view from a controller with different model than my main View. For example:

blic ActionResult Index()
{
//myModel - get Some Types
return View(mymodel);
}
[code]...

View 1 Replies

MVC :: Create A Partial View And A Controller That Will Feed Data To the View?

Jan 27, 2010

Can i create a partial view and a controller that will feed data to the view, and if i render that partial in a Master page, the Data will show on whatever URL i am?

Or is there another way of showing content from database on every page(view)?

View 2 Replies

How To Use An Actionresult To Return Both A View And A Partial View

Feb 17, 2011

How can I use use an actionResult to return both a view and a partial view. Actually in case of an ajax request it should send a partial view else it should send a view.

public ActionResult Test(string Name ="", DateTime? Date= null, string sex="" )
{
myModel model = new myModel(Name, Date, Sex);
if(IsAjaxRequest)
return PartialView("partialView", model)
else
return View(model);
}

View 1 Replies

MVC :: Posting Data From Partial View To Controller

Jan 13, 2011

Im having trouble with posting data from a view that also contains a partialview. Im using a viewmodel that has 2 objects in it. The data that comes from the view is correct and fine, but the data that im trying to get from the partialview is null, or rather the object is null. The partialview doesnt contain that much, the user can check/uncheck some checkboxes and thats it. Heres how the partialview looks like

[Code]....

And heres the View

[Code]....

View 3 Replies

MVC :: Any Difference While Instanciating Controller From Partial View?

Feb 27, 2011

I am new to ASP.NET MVC. I am using MVC 3 and my Issue is as below.Que 1I have created City Master using MVC where My first view is standard and Controller and Model are also standard nothing specific about it. Now when I want to create second view which will be of type partial view so It can be used with other views I am using same controller and model which I am using with first view. But when I try to instanciate the controller from PArtial view it shows non resolution of the controller. The same instanciation is working fine from my first view which is also using same controller.

View 5 Replies

Passing Data From Controller To View Using JSon Object

Mar 4, 2011

I have the following to get the Json abject passed from the controller and populate the various textboxes in the view. However, nothing is happening even though controller is passing a valid Json object. What is wrong with this code?

<script language="javascript" type="text/javascript">
$(document).ready(function() {
var url = '<%=Url.Action("DropDownChange") %>';
$("#vendorID").change(function() {
var selectedID = $(this).val();
if (selectedID != "New Vendor Id") {
//$.post('Url.Action("DropDownChange","Refunds")', function(result) {
$.post(url, { dropdownValue: selectedID }, function(result) {
alert(selectedID);
$("#name").val(result.Name);
$("#city").val(result.City);
$("#contact").val(result.Contact);
$("#address2").val(result.Address2);
$("#address1").val(result.Address1);
$("#state").val(result.State);
$("#zip").val(result.Zip);
});
}
});
});
This is the code in my controller;
public JsonResult DropDownChange(string dropdownValue)
// This action method gets called via an ajax request
{
if (dropdownValue != null && Request.IsAjaxRequest() == true)
{
paymentApplicationRefund =
cPaymentRepository.PayableEntity(dropdownValue);
paymentApplicationRefund.Address1.Trim();
paymentApplicationRefund.Address2.Trim();
paymentApplicationRefund.Name.Trim();
paymentApplicationRefund.City.Trim();
paymentApplicationRefund.Contact.Trim();
paymentApplicationRefund.State.Trim();
paymentApplicationRefund.Zip.Trim();
return Json(paymentApplicationRefund,"application/json");
}
else
{
return null;
}
}

View 3 Replies

MVC :: Trying To Get The Current Nameof The Controller Within A Partial View (under /shared/)?

Dec 17, 2010

im trying to get the current nameof the controller within a partial view (under /shared/).

ViewContext.RouteData.Values["Controller"].ToString() worked well for me. But not with a partial view.

I call the partial view from /Admin/Details. But im getting /Admin/Details/Admin as result. Maybe this is a bug? Here is my code:

[Code]....

View 2 Replies

MVC :: Return A View Of A Different Controller?

Aug 29, 2010

I came upon this when had problem trying to return a view of a different controller.

In controller1, I have view view1.

In Action1 of controller2, I wanted to do something like:

public ViewResult Action1()
{
return View("/Controller1/View1");
}

but, found out, I couldn't do it. So I searched and found this:[URL]

One guy there responded and said that, for my case, it is possible to do things like below:

return View("~/Views/Controller1/View1.aspx");

this is considered an acceptable MVC practice. Is it OK, good, perfect to do so in the asp.net MVC realm?

View 5 Replies

How To Return Partial View From Inside The HtmlHelper

Feb 10, 2011

I have the following code:

public static PartialViewResult DateTime(this HtmlHelper helper)
{
return System.DateTime.Now.ToLongTimeString();
}

and now I want to return a Partial view from inside the DateTime method. But helper instance does not have any method for partial view.

View 2 Replies

MVC :: Post Strongly Typed Partial View's Data To It's Parrent's Controller

Mar 3, 2011

I'm gonna create profile page for my site. This page includes some 'Partial View' and each part posts some data.

My question is: How can I get posted data (strongly typed) from each partial view separately? Something like this:

[HttpPost]

public ActionResult Home(Model1 model1, Model2 model2, ...)

{
return View();

}

View 4 Replies

C# - Submit A Form Via AJAX And Return A Partial View - MVC2?

Dec 17, 2010

Seems like there are a lot of ways to solve this problem.

Currently I make a partial view with a form like so:

[code]....

What are other ways to accomplish the same thing and what are the pros and cons vs what I am doing?

Is Ajax.Form useful?

View 2 Replies

MVC3 Razor - How To Conditionally Quit / End / Return Or Break A Partial View

Feb 15, 2011

With Razor, how do you conditionally quit or end or return or break a partial view?

@if (Model == null)
{
return;
}

View 2 Replies

How To Return Errors To View From Controller Not Tied To A Specific Model Property

Aug 26, 2010

Curious what the best practice is for returning errors to a view from a controller where the error isn't really a validation error, but more like "user not found" or "service timeout" type of errors. (in ASP.NET MVC2 framework)

I've been adding them to the ModelState's model errors, but that doesn't seem appropriate. (although easy to implement and maintain)

Example - A user tries to log in, and their credentials do not match a known user.

View 1 Replies

MVC :: Out Of The Box MVC2 Controller / Delete Controller Is Refusing To Return Any Class Information

Nov 6, 2010

my MVC2 delete and only my delete controller is refusing to return any class information. Its really similar to my edit function and the views are all auto-generated so I don't see the problem.

Function Delete(ByVal id As Integer) As ActionResult

View 4 Replies

MVC :: Pass Parameter From Controller To View And Back To Another Controller?

Aug 16, 2010

I have a simple model where a Person has Gifts. I have a view which is a list of Gifts belonging to one Person.

My problem is with the Create action for a new Gift. I want it to default to the PersonID that we are already viewing the list of Gifts for. I tried simply passing the last PersonID (they are all the same)

Html.ActionLink("Create New", "Create", new { id = Model.Last().PersonID }) which works fine if there is already at least one Gift for that person but if this is the first Gift I don't have a value.

My Gift List controller knows the PersonID I want to pass but the view doesn't.

How do I pass this PersonID from my Gift List controller to my Gift Create controller via the Gift List view? Or is there a better way to do this?

View 2 Replies

Mvc 3 Json Values Not Receiving At Controller?

Mar 22, 2011

the problem is that i am not able to recieve any value in the controller . what could be wrong? the code is here.

[Code]....

View 2 Replies

How To Pass JSON To Controller Action

Mar 6, 2011

I have some textboxes and a table of data created client side that I want pass to a controller as JSON.

I want to use Jquery to enumerate the table.

Assume I have 2 textboxes called name and age. Assume a table with 2 columns. one column with class called phonetype and one column class called phonenumber.

So how do construct the JSON from this?

View 1 Replies

MVC :: Cannot Get JSON Result Back From Controller

Feb 12, 2010

I have been at this for hours and am pretty stuck. I am using MVC2 with VS2010 Beta 2.

Here is my javascript from the view:

[Code]....

Here is my controller code:

[Code]....

I can set a breakpoint in the GetMember method and it does receive the Member_ID parameter correctly. It also correctly returns a member object from my repository (dpR). The function in $.getJSON call that is supposed to receive this result does nothing however. There are no exceptions or javascript errors. It is just silently dying.

View 7 Replies

MVC :: Accepting A Json In A Controller Method?

Oct 10, 2010

I have a JSON object in javascript

it is a collection of Object

How can I pass this object to a controller if i am submitting the form like

$('#myform').submit();

what object type should i give for the parameter to accept this Json

View 5 Replies

Jquery - Get Json Data In Controller Action?

Feb 9, 2011

I have asp.net mvc application. i want to configure the object in jquery and want to pass it to the the action of controller . where as in my script i am using this for configure data for the ajax call:

[Code]....

it does not calls to action in controller. i think here :

var json = $.toJSON(peform);

is not working as expect. is it need to add any js file to reference ? or mistake in syntax?

View 1 Replies

Javascript - Passing JSON To Controller Action

Mar 7, 2011

I have the following javascript. Problem is if I enter one row in the table "ingredients" but I am getting 2 rows in the resulting pass to controller action after seralising into my C# object. But the second object is null? I checked the javascript and the variable "cnt" is 1 not 2. Why would that be?

[code]

$("#Save").click(function () {
var title = $("#recipetitle").val();
var category = $("#category").val();
var preptime = $("#prepTime").val();
var preptimeperiod = $("#lstPrepTime").val();
var cooktime = $("#cookTime").val();
var cooktimeperiod = $("#lstCookTime").val();
var rating = $("#rating").val();
var method = $("#method").val();
var jsontext = '{ "RecipeTitle": "' + title + '",';
jsontext += '"CategoryID":' + category + ',';
jsontext += '"PrepTime":' + preptime + ',';
jsontext += '"PrepTimePeriod":"' + preptimeperiod + '",';
jsontext += '"CookTime":' + cooktime + ',';
jsontext += '"CookTimePeriod":"' + cooktimeperiod + '",';
jsontext += '"Rating":' + rating + ',';
jsontext += '"Method":"' + method + '",';....................

View 1 Replies

MVC :: Using json And Jquery To Send A Form To The Controller?

Nov 21, 2010

i am using json and jquery to send a form to the controller like below, when i click submit validation occers but line is executed even if form is invlid. How can i tell if form validation failed or succeded using javascript?

[Code]....

View 2 Replies

MVC Return Json Result?

Feb 4, 2011

I have a controller that uploads a file. I would like to return a json result with bool success (if successfully uploaded otherwise false) and message (this could be error message that occured OR link to a file OR link to an image, depending on what was uploaded).What's the best way to approach thisI have this

public class UploadedFile
{
public bool Success { get; set; }
public string Message { get; set; }
}

then In my controller I would set Success to true/or/false and Message to <a href OR <img am i on the right track?How would i then parse this in the view so that when image it will show an image, if link show a link, if error simply alert error.

View 2 Replies

How To Get A Method To Return Json In C# And MVC 2 Or 3

Nov 16, 2010

i use JSon to return allot of results when building a website, but find myself writing a a lot of code like this:

[Code]....

and then simply call this function with whatever IEnumerable results i have my question is would i be on the right lines here, what would be the best possible way to do this as it makes no sense to be writing in MVC and OOP but to keep rewriting code to just FROM ?

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved