0
I have a problem that I can’t solve in any way.
Well, I have a project on Asp.NET MVC as follows:
Model
public class Objeto
{
public Objeto()
{
}
public Objeto(string nome, double valor, double percentual)
{
Nome = nome;
Valor = valor;
Percentual = percentual;
}
public string Nome{ get; set; }
public double Valor { get; set; }
public double Percentual { get; set; }
}
Controller
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Dados(Objeto teste)
{
return View(dados);
}
}
View Index:
@using (Ajax.BeginForm("Dados", "Home", new AjaxOptions { OnSuccess = "Sucesso()", OnComplete = "unlockPage()", OnBegin = "lockPage()", OnFailure = "ajaxHandleError" }, new { @id = "meuForm" }))
{
@Html.LabelFor(model => model.Nome)
<br />
@Html.TextBoxFor(model => model.Nome)
<br />
<br />
@Html.LabelFor(model => model.Valor)
<br />
@Html.TextBoxFor(model => model.Valor)
<br />
<br />
@Html.LabelFor(model => model.Percentual)
<br />
@Html.TextBoxFor(model => model.Percentual)
<br />
<br />
<input type="submit" value="Enviar" />
}
View Dados
<label>Os dados inseridos foram:</label>
@Model.Nome
<br />
@Model.Valor
<br />
@Model.Percentual
<br />
Well, what I need to do is introduce View Dados
within the View Index
in a popup
or modal
, using Jquery
or Telerik
, but the data needs to come from controller
, previously sent via POST
by the page Index
.
but you need to present this in a new guide?
– Igor Monteiro
No, I need to present this on the same screen that called, in case the index, and also I cannot lose data from the page that called. In case I should use Ajax, send the data via POST to the controller and return to the page that called it by mounting a popup or modal of Telerik presenting the data page. The problem is how to do it.
– Jedaias Rodrigues
I commented below the use of viewbag, you know?
– Igor Monteiro
you added the
jquery.unobtrusive-ajax.min.js
? if yes you can get the return of the Ajax request in the methodSucesso(response)
, then you will work with the content of the Sponse (return of your Controller) and call the API of your Modal... but the declaration of the method is without the()
, gettingOnSuccess = "Sucesso"
– Tobias Mesquita