Hi
I am using the following code to send values to my database
$("#ordertable").on("click", ".Editbtn", function () {
var status = new Object();
status.Talao = $(this).closest('tr').find(".Talao").val();
status.Status = $(this).closest('tr').find(".Status").val();
status.Obs = $(this).closest('tr').find(".Obs").val();
if (status != null) {
$.ajax({
type: "POST",
url: "/Home/EditPost",
data: JSON.stringify(status),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response != null) {
} else {
alert("Something went wrong");
}
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
<td style="width: 80px;">
@foreach (var item4 in item2.status)
{
@Html.HiddenFor(m => @item4.ID_Programa, new { @class = "ID_Programa" })
@Html.HiddenFor(m => @item4.ID_Linha_Cor, new { @class = "ID_Linha_Cor" })
@Html.HiddenFor(m => @item4.ID_Programa_Malha, new { @class = "ID_Programa_Malha" })
@Html.HiddenFor(m => @item4.ReturnDate, new { @class = "Data_mod" })
<!--Talão-->
@Html.TextBoxFor(m => @item4.Talao, new { @class = "Talao form-control form-control-sm font-weight-bold", disabled = true, style = "width: 80px;" })
}
</td>
<td id="Status">
@foreach (var item4 in item2.status)
{
<!--Html.TextBoxFor(m => item4.Status, new { class = "Status", disabled = true })-->
@Html.DropDownListFor(m => @item4.Status, new List<SelectListItem>
{
new SelectListItem { Text = "Sem malha", Value = "Sem malha"},
new SelectListItem { Text = "No gabinete (dos moldes)", Value = "No gabinete (dos moldes)"},
new SelectListItem { Text = "A testar corte", Value = "A testar corte"},
new SelectListItem { Text = "A bordar", Value = "A bordar"},
new SelectListItem { Text = "Para cortar", Value = "Para cortar"},
new SelectListItem { Text = "Em corte", Value = "Em corte"},
new SelectListItem { Text = "A estampar", Value = "A estampar"},
new SelectListItem { Text = "Para colocar", Value = "Para colocar"},
new SelectListItem { Text = "Em confeção", Value = "Em confeção"},
new SelectListItem { Text = "Para aparar", Value = "Para aparar"},
new SelectListItem { Text = "Para lavar", Value = "Para lavar"},
new SelectListItem { Text = "Para tingir", Value = "Para tingir"},
new SelectListItem { Text = "Para ferros", Value = "Para ferros"},
new SelectListItem { Text = "Para arranjos", Value = "Para arranjos"},
new SelectListItem { Text = "Para embalagem", Value = "Para embalagem"},
new SelectListItem { Text = "Embalado", Value = "Embalado"},
new SelectListItem { Text = "Para controle", Value = "Para controle"},
}, @item4.Status, new { @class = "Status form-control form-control-sm font-weight-bold", disabled = true })
}
</td>
<td id="Obs">
@foreach (var item4 in item2.status)
{
@Html.TextAreaFor(m => @item4.Obs, new { @class = "Obs form-control form-control-sm font-weight-bold", disabled = true, style = "width: 400px;", rows = "1" })
}
</td>
<td style="text-align:right;">
<button class="btn ToEditbtn btn btn-outline-success btn-sm"><span aria-hidden="true"></span>Editar</button>
<button class="btn Editbtn btn btn-outline-success btn-sm" style="display:none"><span aria-hidden="true">Guardar</span></button>
<p style="font-size:10px;">
@foreach (var item4 in item2.status)
{
@item4.Data_mod
}
</p>
</td>
Controller
public ActionResult Index()
{
// more code
return view(result);
}
[HttpPost]
public JsonResult EditPost(Status statusData)
{
Status status = new Status()
{
Talao = statusData.Talao,
Status = statusData.Status,
Obs = statusData.Obs,
};
db.Entry(status).State = EntityState.Modified;
db.SaveChanges();
return Json(status, JsonRequestBehavior.AllowGet);
}
If sending the values together is fine, but my problem is if you insert a separate value, the remaining fields are inserted in white.
Any command that avoids this type of situation or is it a jquery structure problem?
Can you provide the markup and tell us what framework? That will give us a complete picture of what you are trying to do. Also, use dev tools to debug your code. Usually the bug jumps out when you take a close look at what the code is doing.
Below is a working example using ASP.ENT Core.
public class PostModel
{
public int Id { get; set; }
public string Talao { get; set; }
public string Status { get; set; }
public string Obs { get; set; }
}
[HttpGet]
public IActionResult EditPost()
{
List<PostModel> model = PopulateData();
return View(model);
}
[HttpPost]
public IActionResult EditPost([FromBody] PostModel model)
{
return Json(model);
}
Member
20 Points
55 Posts
Send values separately
Feb 11, 2021 05:36 PM|MiguelMi|LINK
Hi
I am using the following code to send values to my database
Controller
If sending the values together is fine, but my problem is if you insert a separate value, the remaining fields are inserted in white.
Any command that avoids this type of situation or is it a jquery structure problem?
Thanks,
All-Star
53101 Points
23661 Posts
Re: Send values separately
Feb 11, 2021 08:58 PM|mgebhard|LINK
Can you provide the markup and tell us what framework? That will give us a complete picture of what you are trying to do. Also, use dev tools to debug your code. Usually the bug jumps out when you take a close look at what the code is doing.
Below is a working example using ASP.ENT Core.
Member
20 Points
55 Posts
Re: Send values separately
Feb 11, 2021 10:57 PM|MiguelMi|LINK
Hi, is webapp in MVC on framework 4.7. I'll check the example soon. Thanks
Member
20 Points
55 Posts
Re: Send values separately
Feb 15, 2021 10:54 AM|MiguelMi|LINK
the solution I found was to change my dopdownlist, to load the value into the table.
thanks for hep.