Skip to content
Loading
  • Employment
  • Type and Purpose
    Purpose:
    Sale: @Html.RadioButton("type", "Sale", new { @checked = true })
    Rent: @Html.RadioButton("type", "Rent")
    Required : @Html.RadioButton("type", "Required")
    Property Type:
    @Html.DropDownListFor(x => x.PropertyTypes, Model.PropertyTypes, "--Select--", new { @id = "ddlPropertyTypes", @class = "dropdown1", @style = "Width:100px;" })
    Property Detail
    Property Title
    @Html.TextBox("title", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = " Property Title is required" })
    Price (in PKR)
    @Html.TextBox("txtPrice", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "Property Price is required" })
    Plot/Land Area
    @Html.TextBox("txtArea", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = " Plot/Land Area is required" })
    Unit
    Covered Area
    @Html.TextBox("txtCoveredArea", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "Covered Area is required" })
    Unit
    Description
    Only 3500 characters remaining
    Property Location
    City:
    @Html.DropDownListFor(x => x.cities, Model.cities, "--Select--", new { @id = "ddlState", @class = "dropdown1" })


    Contact Information
    Full Name *
    @Html.TextBox("txtFullName", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "Full Name is required" })
    @**@
    Phone *
    +92
    -
    @Html.TextBox("txtPhoneAdd", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = " Phone is required" })
    @* *@
    Fax
    @Html.TextBox("txtfax", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = " Fax is required" })
    Mobile *
    +92
    -
    @* @Html.TextBox("txtCoveredArea6", null, new { @class = "form-control" }) *@
    @Html.TextBox("txtMobile", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = " Mobile is required" })
    @* @Html.ActionLink("Submit", "submit", "Property")*@
    @* @Html.ActionLink("Submit Now", "submit", "Property")*@
    @* *@
    @* *@
    This is Employment Information Tab
    @Html.ValidationSummary()


    @* @Html.ActionLink("Create", "Create", "property")*@
    @* *@
    @* *@
    }
    and my controller method is
    public ActionResult SaveRecords()
    {
    String connectionString = "Data Source=ASPKCO-DANISH\\SQLEXPRESS1;Initial Catalog=PakeezaSodagran;Integrated Security=True;";
    SqlConnection conn = new SqlConnection(connectionString);
    conn.Open();
    SqlCommand comm = new SqlCommand("insert into PropertyPosts(title) values(" + Request.QueryString["title"], conn);
    try
    {
    comm.ExecuteNonQuery();
    // Request.QueryString["text"] = null;
    }
    catch (Exception)
    {
    // MessageBox.Show("Not Saved");
    }
    finally
    {
    conn.Close();
    }
    return View();
    }
     
    0
  • Manas Mohapatra
    0
    You have different to get the values from views to controller. Try to use FormCollection object like below code:
    1. public ActionResult CalculateSimpleInterestResult(FormCollection form)  
    2. { 
    3.    if(form != null)
    4.    {
    5.       string principle = form["title"].ToString());
    6.    }   
    7. } 
     http://www.c-sharpcorner.com/UploadFile/3d39b4/getting-data-from-view-to-controller-in-mvc/
    0
  • Mangesh G
    0
    Hey Mark You can do something Like this 
     
     
    Code
    string txtValue= Request["txtPrice"].ToString()
    Code
    Code
    And I am Hoping Your controller ACTION  to be Like this
    Code
    [HttpPost]
    Code
    public ActionResult SaveRecords(FormCollection form)  {
    Code
        string pricee= form["txtPrice"].ToString();
    Code
       }

    Code
    0
  • 0
    i have checked that 
    public ActionResult SaveRecords(FormCollection form)
    {
    if(form != null)
    {
    string principle = form["title"].ToString();
    }
    string Title=Request.QueryString["title"];
    String connectionString = "Data Source=ASPKCO-DANISH\\SQLEXPRESS1;Initial Catalog=PakeezaSodagran;Integrated Security=True;";
    SqlConnection conn = new SqlConnection(connectionString);
    conn.Open();
    SqlCommand comm = new SqlCommand("insert into PropertyPosts(title) values(" + Request.QueryString["title"], conn);
    try
    {
    comm.ExecuteNonQuery();
    // Request.QueryString["text"] = null;
    }
    catch (Exception)
    {
    // MessageBox.Show("Not Saved");
    }
    finally
    {
    conn.Close();
    }
    return View();
    }
    and it is still null , i also checked the Request["title"].toString(); it also null weather i and putting text in textbox and id is also same title  
    0
  • 0
    Code
    [HttpPost]
    when i add the httppost attribute above my method then it does not come to this method while i debug application it just say, it did not come to my SaveRecords Method if i omit the httppost then i comes to debug point

    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /Property/SaveRecords


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET
     
    Version:4.6.1055.0 
    0
  • Salman Beg
    0
    Requested URL: /Property/SaveRecords
    i think In "Property" Controller there is no action method "SaveRecords" present. So please check at your end whethere SaveRecords method is present in Property Controller or not.
    thanks. 
    0
  • 0
    I have that method present check the screen shot 
    0
  • Mangesh G
    0
    [HttpPost]
    public ActionResult Create(FormCollection collection)
    {
    try

    {


    if (collection != null)
    {
    string userName = collection["txtdetails"].ToString();
    }


    // TODO: Add insert logic here

    return View();
    }
    catch(Exception ex)
    {
    return View();
    }
    }
     
     
    View
    ==================================
     
    @{
    ViewBag.Title = "Create";
    }

    Create




    @using (Html.BeginForm("Create", "Sample"))
    {




    @Html.TextBox("txtid","111");

    }



     
    0
  • Manas Mohapatra
    0
    You are getting 404 error(File not found) because SaveRecords() method returns return View(). It means it looks for SaveRecords.cshtml file as view. So better to provide the view name when you returns.
     
    return View("MyView");
     
    http://stackoverflow.com/questions/26359192/how-to-return-actionresult-with-specific-view-not-the-controller-name 
     
    If it helps you please accept the answer. 
    0
  • 0
    [HttpPost]
    public ActionResult Index(string txtPrice)
    {
    return View();
    }
    0