I create a new class in my mvc project. The following are defined as properties;
public class InputBranch
{
public int adminID { get; set; }
public string authorized { get; set; }
public float lat { get; set; }
public float lng { get; set; }
public int icon { get; set; }
}
I am sending a new object of type Input Branch as a parameter to a structure that works with the post method.
My goal is not to manually change it when a new field arrives in the inputBranch class (actually the database table), one by one, wherever it is bound.
Controllers in code;
[HttpPost]
public JsonResult addBranch(InputBranch branchData)
{
databaseEntities st = new databaseEntities();
branch br = new branch
{
ADMIN = branchData.adminID,
NAME = branchData.authorized,
LAT = branchData.lat,
LNG = branchData.lng,
ICON = branchData.icon,
STATUS = true,
LAST_LOGIN = DateTime.Now
};
st.branchs.Add(br);
st.SaveChanges();
return Json(true, JsonRequestBehavior.AllowGet);
}
But here is the problem. After the input in the html form, I post it with Jquery and again, I do the input one by one manually, which I don't want. The code is here;
$.post("/JSON/addBranch",
{
adminID: adminID,
authorized: branchName,
lat: marker._latlng.lat,
lng: marker._latlng.lng,
icon: iconNo
}, function (t, e) { console.log("success"); });
Does anyone have a different way or a best practice suggestion for this?
My goal is to connect these parameters to a single center everywhere and execute the get-post logic from there.