0

So i want to create a person and add it to my table if i dont have the same name already in my table. i have this code in my controller

hesaplamaEntities hsb = new hesaplamaEntities();
[HttpPost]
public ActionResult Create(MyTable p)
    {

        MyTable obj = hsb.MyTable.Find(p);

        if (obj.propname == null)
        {
            hsb.MyTable.Add(p);
            hsb.SaveChanges();

           return RedirectToAction("Create", "Home");

        }
        else
        {
            return HttpNotFound();
        }

and this is my View :

@using (Html.BeginForm("Create", "Home", FormMethod.Post, new { @class = 
"form-horizontal", enctype = "multipart/form-data" }))
{


<div class="row">
    <div class="form-horizontal">
        <div class="form-group">
            <div class="col-md-12">
                <label class="col-sm-2 control-label">Name</label>
                <div class="col-sm-10">
                    @Html.TextBoxFor(m => m.propname, new { @class = "form-control" })
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-12">
                <label class="col-sm-2 control-label">kod</label>
                <div class="col-sm-10">
                    @Html.TextAreaFor(m => m.propkod, new { @class = "form-control" })
                </div>
            </div>
        </div>

    </div>
</div>
<div class="panel-footer">
    <div class="row">
        <div class="col-sm-9 col-sm-offset-3">
            <div class="btn-toolbar pull-right">
                <input type="submit" value="save" class="btn btn-primary" />
            </div>
        </div>
    </div>
</div>

}

and this is my Model :

public partial class MyTable
{
    public int ID { get; set; }
    public string propkod { get; set; }
    public string propname { get; set; }

}

i am having this error when i am trying to add person : he specified parameter type 'WebApplication7.Models.MyTable' is not valid. Only scalar types, such as System.Int32, System.Decimal, System.DateTime, and System.Guid, are supported.

and its showing me the error in this line : HesapTemel obj = hsb.HesapTemels.Find(p);

what is the probleme exactly ?

0 Answers0