1
Controller:
[HttpPost]
public ActionResult Listar_Json()
{
var id = 5;
var search = Request["search[value]"]; //Aqui pega valor digitado no input, digamos que ele digitou 100.000,01
var query = database.Posts.Join(database.Post_Metas,
post => post.ID,
meta => meta.Post_ID,
(post, meta) => new
{
valor1 = post.Money1, //100000,01
valor2 = meta.Money2 //100000,02
})
.Where(x => x.Post.ID == id)
.ToList();
foreach (var item in query )
{
item.valor1 = item.valor1 ???? //100.000,01
}
query = query
.Where(x => (x.Money1.ToString() ?? "").Contains(search)
.ToList();
return Json(new { data = query }, JsonRequestBehavior.AllowGet);
}
View:
<table id="data_grid" class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Valor1</th>
<th>Valor2</th>
</tr>
</thead>
</table>
I want to return value 100000,01 for 100.000.01. For that, I need to use a foreach
to modify. I cannot modify valor1
, because it says it can’t be assigned, it’s read-only.
How can I modify value?
It’s not enough to make a
valor1 = string.Format("{0:N}",post)
, nay?– Felipe Avelar
@Felipeavelar, I already tried this tbm, I get error:
LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object)' method, and this method cannot be translated into a store expression.
– Matheus Miranda
So, I believe that making a select after Where is best.
– Felipe Avelar
@Felipeavelar, I get the same mistake, there’s a way I get this thing out of "read-only" ?
– Matheus Miranda
It’s read-only and you really can’t assign, what do you want? Display in a View???
– novic
That’s right Virgil, I intend to display in the view.
– Matheus Miranda
@Matheusmiranda posts her
View
yourController
and the responsible method so that I can propose something to you! do not need to format like this.– novic
@Virgilionovic edited post. In the database is recorded as
100000,01
say user typed in100.000,01
. How can I get the line that contains100000,01
?– Matheus Miranda
are you filtering by currency value? the user on the screen typed in the Brazilian standard and the Bank is in different format? is that it??? if you need to filter in the database by the data sent from the screen?
– novic
@Virgilionovic as in !!!
– Matheus Miranda
@Matheusmiranda I believe you have to save the value in the database being Numeric even (decimal house with . in sql server, for example). If the user type 100,000.01, you would have to remove the dots and then convert to decimal again by formatting the number. But this has to be before passing the value to Ingl, because if using format it will give way even as it will try to convert the method into a valid sql.
– Grupo CDS Informática