0
So, we have a website that when passing a user’s code, it shows the location of the same.
Example of the URL:
http://npaa1215.example.com/gisb_prod/integration/coordUser.aspx?codUser=30071665&zoom=15
In the URL we can pass the parameter codUser
.
In my application I have these codes and would like to insert in the codUser field
In the example the site pointing to the user codUser=30071665
This is my Barcoviewmodel
[Key]
public Guid Id { get; set; }
[Required(ErrorMessage = "Campo Obrigatório")]
public string Nome { get; set; }
[Required(ErrorMessage = "Campo Obrigatório")]
public bool Ativo { get; set; }
[Display(Name = "Registro SAP")]
[Required(ErrorMessage = "Campo Obrigatório")]
public int SapId { get; set; }
[Display(Name = "Tancagem Água")]
[Required(ErrorMessage = "Campo Obrigatório")]
public int CapacidadeAgua { get; set; }
[Display(Name = "Tancagem óleo")]
[Required(ErrorMessage = "Campo Obrigatório")]
public int CapacidadeOleo { get; set; }
[Required(ErrorMessage = "Campo Obrigatório")]
public int Velocidade { get; set; }
[Required(ErrorMessage = "Preencha o campo E-mail")]
[MaxLength(100, ErrorMessage = "Máximo {0} caracteres")]
[EmailAddress(ErrorMessage = "Preencha um E-mail válido")]
[Display(Name ="E-mail")]
public string Email { get; set; }
And on my controller I thought I’d do something like this:
string url = http://npaa1215.example.com/gisb_prod/integration/coordUser.aspx?codUser={0}&zoom=15;
private string GetLocation(BarcoViewModel barcoViewModel)
{
return string.Format(url, barcoViewModel.SapId);
}
But it won’t work, someone would have an example of how I insert this into view?
As I would for the method of controller return that url with the parameter?
********EDIT*******
Based on colleagues' response
That’s my Controller code:
http://npaa1215.example.com/gisb_prod/integration/coordUser.aspx?codUser=30071665&zoom=15
[HttpGet]
private string GetLocation(BarcoViewModel barcoViewModel)
{
return string.Format(url, barcoViewModel);
}
[HttpPost]
public RedirectResult RedirectTo(BarcoViewModel barcoViewModel)
{
string destination = GetLocation(barcoViewModel);
return RedirectPermanent(destination);
}
This is the View
<a href="@Url.Action("RedirectTo","Barcos", new { id = item.SapId })" class="btn btn-danger">
<span title="Excluir" class="glyphicon glyphicon-alert"></span>
</a>
Only that even making these additions, I still get the following error:
The Url you want to return is from your own application?
– Victor Laio
What exactly are you trying to do? redirect to this address or simply return the string?
– Leandro Angelo
@Victorlaio this url is from another system, it is already running on the internet, my idea is to insert the"Sapid" of my viewmodel, in the field "codUser". then the user when clicking the button, for example it is redirected to this site, only with the parameter q I passed.
– Jhensen
@Leandroangelo redirect to this site, only passing in the field "codeUser" the property "Sapid" of my system. Ai when the user clicks on a button, for example, it redirects the user to that site.
– Jhensen
I put 2 possible solutions for you friend.
– Victor Laio