I'm trying to send multiple objects via FormMethod.Post, but the problem is that only the value of the first one is saved and the value of second one is the same as first. The problem is probably in the Razor syntax which I'm pretty new at, here is the code I'm using:
@using (Html.BeginForm("chAdress", "Adress", FormMethod.Post))
{
@Html.Label("Number")
@Html.TextBoxFor(model => model.Number)
@Html.ValidationMessageFor(model => model.Number)
@Html.Label("Distance")
@Html.TextBoxFor(model => model.Distance)
@Html.ValidationMessageFor(model => model.Distance)
@Html.Label("New Number")
@Html.TextBoxFor(model1 => model1.Number)
@Html.ValidationMessageFor(model1 => model1.Number)
@Html.Label("New Distance")
@Html.TextBoxFor(model1 => model1.Distance)
@Html.ValidationMessageFor(model1 => model1.Distance)
<button type="submit">Change Adress</button>
}
And here is the controller that should make the change:
public void chAdress(Adress model, Adress model1)
{
prepareConnection();
string distance = model.Distance.ToString();
string newDistance = model1.Distance.ToString();
Dictionary<string, object> queryDict = new Dictionary<string, object>();
queryDict.Add("distance", distance);
queryDict.Add("newDistance", newDistance);
var query = new Neo4jClient.Cypher.CypherQuery("start n=node(*) where (n:Adress) and exists(n.distance) and n.distance =~ {distance} set n.distance = {newDistance} return n",
queryDict, CypherResultMode.Set);
List<Adress> adrese = ((IRawGraphClient)client).ExecuteGetCypherResults<Adress>(query).ToList();
}
After running in debug mode, I see that the value of distance is always the same as the newDistance, what is the best way to fix this issue?
Views can only be typed to one model. You appear to be trying referencing a Model and Model1 in your view. You should create a new ViewModel to contain all properties that you want to return from your form and then, if needed, process that from your controller into the distinct objects you need.
Since you actually have just one model (but are trying to use it like 2) you are overwriting the properties of the previously set values.